C ++中的原始字符串文字
在C++11及更高版本中,有一个称为Rawstring的概念。在字符串中,我们使用不同的字符,例如\n,\t等。它们具有不同的含义。\n用于将光标返回到下一行,\t生成制表符等。
如果我们想在输出中打印这些字符而看不到它们的效果,则可以使用原始字符串模式。为了使字符串成为原始字符串,我们必须在字符串之前添加“R”。
Input: A string "Hello\tWorld\nC++" Output: "Hello\tWorld\nC++"
算法
Step 1: Get the string Step 2: Use R before string to make it raw string Step 3: End
范例程式码
#include<iostream>
using namespace std;
main() {
string my_str = "Hello\tWorld\nC++";
string raw_string = R"Hello\tWorld\nC++";
cout << "Normal String: " << endl;
cout << my_str <<endl;
cout << "RAW String: " << endl;
cout << raw_string;
}输出结果
Normal String: Hello World C++ RAW String: Hello\tWorld\nC++
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短