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 毕业女孩祝福语简短独特