Using variables in system() function c++

前端 未结 3 1248
慢半拍i
慢半拍i 2020-12-30 14:00


  string line;
  ifstream myfile (\"aaa.txt\");
  getline (myfile,line);
  system(\"curl.exe -b cookie.txt -d test=\"+line+\"  

        
3条回答
  •  遥遥无期
    2020-12-30 14:25

    Build the string you're passing to system() with a stringstream!

    #include 
    #include 
    #include 
    using namespace std;
    
    int main(void){
        string line;
        ifstream myfile("aaa.txt");
        getline(myfile,line);
        stringstream call_line;
        call_line << "curl.exe -b cookie.txt -d test=" << line << "  http://example.com");
        system(call_line.str().c_str());
    }
    

提交回复
热议问题