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