C 學習筆記

2021-07-05 09:37:50 字數 825 閱讀 4078

標準庫string型別

首先string的使用是需要先宣告#include

string的初始化:

string s1;

s1 = "hello world";//也可以string s1 = "hello world";

string s2(s1);//將s2初始化為s1的副本

string s3("hello world");

string s4(n,'c');//將s4初始化為n個c

對於未知數目的string可以採用

string strword;

while(cin>>strword)

while(getline(cin,strword))

//以上均為ctrl+z可以輸入終止輸入符or達到內部終止條件

string s1 = "hello";

string s2 = "world";

string s3 = s1 +s1;//對

string s3 = "hello" + "world";//error

string s4 = "hello" + s2;//對

for(string::iterator it = s1.begin();it != s1.end();it++)

//iterator遍歷

for(string::size_type st = 0;st != s1.size();st++)

{ cout

———-待續…

C 學習筆記( )

一 語法 迴圈 foreach 型別識別符號 in 表示式 code 用法 例子int temp foreach int num in temp 每次從temp取乙個元素賦給num直至取完 console.writeline n num 每行顯示乙個元素 執行結果 c 中唯讀 只寫控制 class ...

C 學習筆記

1.函式特徵 有函式頭和函式體 接受乙個引數 返回乙個值 需要乙個原型。2.c 命名規則 在名稱中只能使用字母字元 數字和下劃線 名稱的第乙個字元不能是數字 區分大寫字母和小寫字母 不能將c 關鍵字用作名稱 以兩個下劃線或下劃線和大寫字母打頭的名稱被保留給實現 編譯器及其使用的資源 使用,以乙個下劃...

c 學習筆記

屬性 屬性開頭字母大寫 屬性可以判斷輸入的非法值 屬性本身不儲存值 依靠字段 索引器 using system using system.collections.generic using system.linq using system.text namespace b try catch exc...