cannot convert 'std::basic_string' to 'const char*' for argument '1' to 'int system(const char*)'

前端 未结 6 1265
无人及你
无人及你 2020-11-29 07:18

I get this error: \"invalid operands of types \'const char*\' and \'const char [6]\' to binary \'operator+\'\" when i try to compile my script. Here should be the error:

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 08:04

    std::string + const char* results in another std::string. system does not take a std::string, and you cannot concatenate char*'s with the + operator. If you want to use the code this way you will need:

    std::string name = "john";
    std::string tmp = 
        "quickscan.exe resolution 300 selectscanner jpg showui showprogress filename '" + 
        name + ".jpg'";
    system(tmp.c_str());
    

    See std::string operator+(const char*)

提交回复
热议问题