【C++grammar】vector类和字符串字面量
生活随笔
收集整理的這篇文章主要介紹了
【C++grammar】vector类和字符串字面量
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
C++的vector類
用數組存放數據時,容量大小不可變,vector對象容量可自動增大。
vector的操作:
調用push_back函數時,vector對象的容量可能會增大。
觀察下列操作對vector的影響:
字符串字面量
C++11原始字符串字面量
語法: R “delimiter( raw_characters )delimiter”
“Raw String literals”在程序中寫成什么樣子,輸出之后就是什么樣子。我們不需要為“Raw String literals”中的換行、雙引號等特殊字符進行轉義。
C++14的字符串字面量
C++14將運算符 ""s 進行了重載,賦予了它新的含義,使得用這種運算符括起來的字符串字面量,自動變成了一個 std::string 類型的對象。
auto hello = "Hello!"s; // hello is of std::string type auto hello = std::string{"Hello!"}; // equals to the above auto hello = "Hello!"; // hello is of const char* type已知’\0’在字符串里面代表結束符號
#include <string> #include <iostream> int main() {using namespace std::string_literals;std::string s1 = "abc\0\0def";std::string s2 = "abc\0\0def"s;std::cout << "s1: " << s1.size() << " \"" << s1 << "\"\n";std::cout << "s2: " << s2.size() << " \"" << s2 << "\"\n"; }總結
以上是生活随笔為你收集整理的【C++grammar】vector类和字符串字面量的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《蜀四贤咏》第六句是什么
- 下一篇: leetcode 90. 子集 II 思