C++ | 通过命令行运行exe时 参数中有空格的解决办法

当通过命令行运行exe,main函数需要设置参数时,我们需要在命令行中以如下的方式运行:

>可执行文件名称 参数

eg:demo.exe 中main函数需要一个string 参数:"hello",在命令行中需要这样写:

>demo.exe hello或者

>demo.exe "hello"

eg:demo.exe 中main函数需要一个string 参数:" I am a chinese",在命令行中需要这样写:

>demo.exe "I am a chinese"

即:一个字符串中有空格时,需要将该字符串用引号括起来

扫描二维码关注公众号,回复: 11756474 查看本文章

eg:demo.exe 中main函数需要json参数:" {"text":"hello"}",在命令行中需要这样写:

>demo.exe {\"text\":\"hello\"}

eg:demo.exe 中main函数需要json参数:" {"text":"hello world"}",在命令行中需要这样写:

>demo.exe {\"text\":"\"hello world\""} 或者

>demo.exe "{\"text\":\"hello world\"}"

猜你喜欢

转载自blog.csdn.net/weixin_39766005/article/details/108672339