C 的STL庫常用API string

2021-07-16 06:06:19 字數 1038 閱讀 9745

int copy(char *s, int n, int pos=0) const;

把當前串中以pos開始的n個字元拷貝到以s為起始位置的字元陣列中,返回實際拷貝的數目。注意要保證s所指向的空間足夠大以容納當前字串,不然會越界。

string &erase(int pos=0, int n=npos); //刪除pos開始的n個字元,返回修改後的字串

wstring s2ws(const

string &s)

如果我們想建立兩個版本的程式,乙個處理ascii字串,另乙個處理unicode字串,最好的解決辦法是編寫出既能按ascii編譯又能按unicode編譯的單一源**。把以下**加入到程式中,只要修改乙個巨集就能滿足我們的要求。

#ifdef _unicode

typedef wstring tstring;

typedef wchar_t tchar;

#define _t(x) l ## x

#else

typedef string tstring;

typedef char tchar;

#define _t(x) x

#endif

用法 stl 常用C 標準模板庫(STL)

定義 vectorinstname typename可以是任何基本型別,結構體或stl標準容器.2.遍歷訪問 1 通過下標 2 通過迭代器 for vector iterator it vi.begin it vi.end it vec i 和 vi.begin i 等價 3.常用函式 push b...

程式設計常用的C 模板庫(STL)

棧 include stackname bool empty void pop void push const type type top size type size 佇列 include queuename bool empty void pop void push const type typ...

C 標準模板庫 STL 常用演算法

algorithm中的函式 find start,end,value start搜尋的起點,end搜尋的終點,要尋找的value值 find a.begin a.end value find a,a length,val 所有的返回,均是迭代器 容器 或指標 陣列 而非是直觀感覺上的索引下標。如果在...