how to prevent losing double quotes in argv?

后端 未结 2 1807
抹茶落季
抹茶落季 2021-01-21 10:15

Ok, I know I can do loop like this:

for (int i=1; i<=argc-1;i++) {
  cout << argv[i] << endl;
}

But this way double quotes are l

相关标签:
2条回答
  • 2021-01-21 11:02

    It's the shell that removes the quotes. If you want the shell to pass the quotes to you, you have to escape them:

    $ ./my-program \"hello\ world\"
    

    Note that I escape the space as well, to make it one argument.

    0 讨论(0)
  • 2021-01-21 11:07

    When you need the original command line, your can use the GetCommandLine() API function.

    0 讨论(0)
提交回复
热议问题