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 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短