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++