日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

C++11新特性探索:原始字符串字面值(raw string literal)

發布時間:2025/3/12 c/c++ 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++11新特性探索:原始字符串字面值(raw string literal) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原始字符串字面值(raw string literal)是C++11引入的新特性。

原始字符串簡單來說,“原生的、不加處理的”,字符表示的就是自己(所見即所得),引號、斜杠無需 “\” 轉義,比如常用的目錄表示,引入原始字符串后,非常方便。

格式如下:

R"(原始字符串)";

廢話不多說,上代碼:

比如顯示RedistList目錄,用redist_path1顯然是錯的,C++ 11之前需要用redist_path2這種方式轉義,當我們引入原始字符串的話,非常方便。

順便來個流行的佛祖保佑,永無bug。

#include "stdafx.h" #include <iostream> #include<string>int main() {std::string redist_path1 = "C:\Program Files (x86)\Microsoft.NET\RedistList";std::string redist_path2 = "C:\\Program Files (x86)\\Microsoft.NET\\RedistList";std::string redist_path3 = R"(C:\Program Files (x86)\Microsoft.NET\RedistList)";std::string redist_path4 = R"(C:\\Program Files (x86)\\Microsoft.NET\\RedistList)";std::cout << "redist_path1: "<< redist_path1 << std::endl;std::cout << "redist_path2: " << redist_path2 << std::endl;std::cout << "redist_path3: " << redist_path3 << std::endl;std::cout << "redist_path4: " << redist_path4 << std::endl;std::string fozu = R"(_ooOoo_o8888888o88" . "88(| -_- |)O\ = /O____/`---'\____. ' \\| |// `./ \\||| : |||// \/ _||||| -:- |||||- \| | \\\ - /// | || \_| ''\---/'' | |\ .-\__ `-` ___/-. /___`. .' /--.--\ `. . __."" '< `.___\_<|>_/___.' >'"".| | : `- \`.;`\ _ /`;.`/ - ` : | |\ \ `-. \_ __\ /__ _/ .-` / /======`-.____`-.___\_____/___.-`____.-'======`=---=')";std::cout << fozu << std::endl;return 0; }

編譯運行查看結果:

?

總結

以上是生活随笔為你收集整理的C++11新特性探索:原始字符串字面值(raw string literal)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。