C++新特性探究(四):Raw String Literals

在这里插入图片描述
  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;
}

猜你喜欢

转载自blog.csdn.net/weixin_43297891/article/details/113488233
今日推荐