Rel*_*lla 0 c++ string replace
所以我尝试std::replace(diff_path.begin(), diff_path.end(), "\\", "/");但似乎没有在我的视觉工作室编译.怎么做 - 怎么把所有\变成/字符串的内部?
Error 3 error C2446: '==' : no conversion from 'const char *' to 'int' c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 1311 1 CloudServerPrototype
Error 5 error C2440: '=' : cannot convert from 'const char [2]' to 'char' c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 1312 1 CloudServerPrototype
Error 4 error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]' c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 1311 1 CloudServerPrototype
Run Code Online (Sandbox Code Playgroud)
您需要使用字符文字,而不是字符串文字:
std::replace(diff_path.begin(), diff_path.end(), '\\', '/');
^~~~ ^~~
Run Code Online (Sandbox Code Playgroud)
所述value_type的std::string是char(在一个串中的每个元素是一个单个字符).