C++ | Solutions for spaces in the parameters when running exe through the command line

When running the exe through the command line and the main function needs to set parameters, we need to run it in the command line as follows:

>Executable file name parameter

 

The main function in eg:demo.exe requires a string parameter: "hello", which needs to be written in the command line:

>demo.exe hello or

>demo.exe "hello"

 

The main function in eg:demo.exe requires a string parameter: "I am a chinese", which needs to be written in the command line:

>demo.exe "I am a chinese"

That is: when there are spaces in a string, you need to enclose the string in quotation marks

 

The main function in eg:demo.exe requires a json parameter: "{"text":"hello"}", which needs to be written in the command line:

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

 

The main function in eg:demo.exe requires a json parameter: "{"text":"hello world"}", which needs to be written in the command line:

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

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

 

Guess you like

Origin blog.csdn.net/weixin_39766005/article/details/108672339