Convert command line argument to string

后端 未结 7 1181
囚心锁ツ
囚心锁ツ 2021-01-31 08:43

I have a program that reads hard-coded file-path and I want to make it read file-path from command line instead. For that purpose I changed the code like this:

#         


        
7条回答
  •  南笙
    南笙 (楼主)
    2021-01-31 09:13

    No need to upvote this. It would have been cool if Benjamin Lindley made his one-liner comment an answer, but since he hasn't, here goes:

    std::vector argList(argv, argv + argc);

    If you don't want to include argv[0] so you don't need to deal with the executable's location, just increment the pointer by one:

    std::vector argList(argv + 1, argv + argc);

提交回复
热议问题