C ++程序中的原始字符串文字
在本文中,我们将讨论C++中的原始字符串文字,其含义和示例。
C++中有转义字符,例如“\n”或“\t”。当我们尝试打印转义字符时,它将不会显示在输出中。为了在输出屏幕上显示转义字符,我们使用原始字符串文字,方法是使用R”(带有转义字符的字符串)”。在字符串前面使用R后,转义字符将显示在输出上。
示例
让我们借助示例来了解这一点
#include <iostream>
using namespace std;
int main(){
string str = "tutorials\npoint\n" ;
// A Raw string
string str_R = R"(tutorials\npoint\n)";
cout <<"String is: "<<str << endl;
cout <<"Raw String is: "<<str_R;
return 0;
}输出结果
如果我们运行上面的代码,它将生成以下输出-
String is: tutorials point Raw String is: tutorials\npoint\n
示例
#include <iostream>
using namespace std;
int main(){
string str = "tutorials\ttoint\t" ;
// A Raw string
string str_R = R"(tutorials\tpoint\t)";
cout <<"String is: "<<str << endl;
cout <<"Raw String is: "<<str_R;
return 0;
}输出结果
如果我们运行上面的代码,它将生成以下输出-
String is: tutorials toint Raw String is: tutorials\tpoint\t
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短