C primer 學習筆記 字串

2021-07-06 09:37:20 字數 802 閱讀 9952

初始化和定義

string s1;

string s2=s1;

string s1("hello");//直接初始化

string s2="hello";//拷貝初始化

字串操作

string s;

s.empty();

s.size();//返回值型別string::size_type

getline(cin,s);//引數:流引數,字串;返回s 的流引數

s1+s2;//+倆側必須有一項為string物件,字串面值不是

s1==s2;s1>s2;

字串上字元操作

for(declaration:experssion)

statement

下標運算子 ,引數型別string::size_type

#include

#include

#include

using

std::string;

using

std::cout;

int main()

for (auto &c : s)

c = toupper(c);

cout

<< s;

cout

<< punch_cnt;

return

0;}

《C primer 讀書筆記》 字串

c 提供了兩種字串的表示 c 風格的字串和標準 c 引入的 string 類型別 1.c 風格的字串 字串被儲存在乙個字元陣列中,一般通過乙個char 型別的指標來操縱它 必須包含相關的 c 標頭檔案 include提供一系列函式,如 返回字串的長度 int strlen const char 比較...

字串 學習筆記

這篇部落格只是記錄一下我在做題過程中碰到的一些關於字串巧妙的處理方式 可能只對我這個菜雞來說相對巧妙吧 1 stringstream的使用 第一次碰到stringstream的使用是在紫書上面p112,題目是uva10815。前幾天補字串的題目的時候在 洛谷p1308統計單詞數 也碰到了一題可以使用...

C 風格字串 (c primer)

字串字面值的型別就是 const char 型別的陣列。c 從 c 語言繼承下來的一種通用結構是c 風格字串,而字串字面值就是該型別的例項。實際上,c 風格字串既不能確切地歸結為 c 語言的型別,也不能歸結為 c 語言的型別,而是以空字元 null 結束的字元陣列 char ca1 no null,...