string標準庫型別 C

2021-05-01 16:32:19 字數 871 閱讀 2654

c++中string的學習體會:

string:

1).不允許把兩個字串字面值連線起來,乙個string物件+字串字面值返回的是string物件.

string::size_type只是string裡方便移植性的定義的一種型別

2).cout<<"/""<

#include

using namespace std;

int main()

4).讀入兩個string物件,測試他們長度是否相等

#include "stdafx.h"

#include

#include

using namespace std;

int main()

5).從標準輸入讀取多個string物件,把它們連線到一起存放到更大的string物件中,並輸出連線後的物件,改寫程式,將連線後相鄰的string物件以空格隔開

#include "stdafx.h"

#include

#include

using namespace std;

int main()

改寫後:以空格隔開輸出:

#include "stdafx.h"

#include

#include

using namespace std;

int main()

6).從string物件中去掉標點符號,要求輸入到程式中的字串必須含有標點符號,輸出結果則是去掉標點符號後的string物件.

#include "stdafx.h"

#include

#include

using namespace std;

int main()

C 標準庫string型別

c 組成 基本資料型別和抽象資料型別標準庫 只需知道抽象資料型別支援的操作而不需關心內部表示 命名空間兩種使用方法 using std name 和 using namespace std 標準庫string型別和字串字面值不是同一型別 具體區別?getline 函式 string line get...

C 標準庫string型別

標準庫的string型別 include include using namespace std 或者可以這樣 using std string using std cin using std cout int main 12.下標操作可用作左值 string str some string for...

C 標準型別庫string

string初始化方式 int main getline輸出一整行 getline 引數 輸入流,string物件 讀取給定內容,遇到換行符停止 換行符也被讀取進去了 它返回乙個流的引數。include includeusing namespace std int main string s whi...