Convert command line argument to string

后端 未结 7 1180
囚心锁ツ
囚心锁ツ 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 08:59

    It's already an array of C-style strings:

    #include 
    #include 
    #include 
    
    
    int main(int argc, char *argv[]) // Don't forget first integral argument 'argc'
    {
      std::string current_exec_name = argv[0]; // Name of the current exec program
      std::vector all_args;
    
      if (argc > 1) {
        all_args.assign(argv + 1, argv + argc);
      }
    }
    

    Argument argc is count of arguments plus the current exec file.

提交回复
热议问题