#include <iostream> #include <cstring> using namespace std; void set_temp_iface(string iface) { string temp_iface; temp_iface.append(iface); cout << temp_iface << endl; } int main(int argc, char* argv[]) { if(strcmp(argv[1], "iface") == 0) set_temp_iface(string(argv[2])); return 0; } 

And the result is invisible. In the console, an empty string. What could be the reason? G ++ 5.4 compiler

  • one
    Show the minimum testable example that reproduces the problem. - Vlad from Moscow
  • And also indicate which compiler you are using. - Vlad from Moscow
  • one
    @Vova Polischuck And 1) it is not necessary to use command line arguments. Just declare std :: string s ("iface"); And use it. 2) Paste the headers so that the program is ready for compilation so that it can be copied one by one and run on your computer. - Vlad from Moscow
  • one
    @Vova Polischuck Nevertheless, you did a useful job and made sure that the append works correctly. Now extend this basic example gradually until the problem arises. - Vlad from Moscow
  • one
    Your algorithm is not built correctly. string temp_iface; - it is declared locally, why append is made to it - it is not clear, since the variable is initially empty, and then arg [2] is displayed. This code can be written easier. If you are working with char [] then strcat or vsprintf or the like will suit you. - nick_n_a

0