C/C++中提供了字符串,字符串的转义序列,给输出带来了很多不便,如果需要原生义的时候,需要反转义,比较麻烦。
C++提供了R"( )",原生字符串,即字符串中无转义,亦无需再反义。但是注意( )中的 )" 会导致提前结束。
示例:
附上例代码:
//小问学编程
#include <iostream>
using namespace std;
string path = "C:\Program Files (x86)\alipay\aliedit\5.1.0.3754";
string path2= "C:\\Program Files (x86)\\alipay\\aliedit\\5.1.0.3754";
string path3= R"(C:\Program Files (x86)\alipay\aliedit\5.1.0.3754)";
string path4= R"(C:\Program "Files" (x86)\\alipay\aliedit\5.1.0.3754)";
int main()
{
cout<<path<<endl;
cout<<path2<<endl;
cout<<path3<<endl;
cout<<path4<<endl;
return 0;
}