Convert command line argument to string

后端 未结 7 1172
囚心锁ツ
囚心锁ツ 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:58

    Because all attempts to print the argument I placed in my variable failed, here my 2 bytes for this question:

    std::string dump_name;
    
    (stuff..)
    
    if(argc>2)
    {
        dump_name.assign(argv[2]);
        fprintf(stdout, "ARGUMENT %s", dump_name.c_str());
    }
    

    Note the use of assign, and also the need for the c_str() function call.

提交回复
热议问题