C++ 中的原生字符串文字
在 C++11 及以上版本中,有一个概念叫做 Raw 字符串。在字符串中,我们使用 \n、\t 等不同的字符。它们有不同的含义。\n 用于将光标返回下一行,\t 生成制表符等。
如果我们希望在输出中打印这些字符而不看到它们产生的效果,我们可以使用 Raw 字符串模式。要将一个字符串转换为 Raw 字符串,我们必须在字符串前添加 "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++
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP