《C++標準程序庫》學習備忘

鉅細靡遺·井然有序(侯捷譯序)
孟巖譯序
目錄
前言
致謝
1.關於本書
2.C++及其標準程序庫簡介
3.一般概念
4.通用工具
5.Standard Template Library(STL,標準模板庫)
6.STL容器(STL Container)
7.STL 迭代器(STL Iterators)
8.STL 仿函數(functors)(又名函數對象,function objects)
9.STL算法(STL Algorithms)
10.特殊容器(Special Containers)
11.Strings(字符串)
12.數值(Numerics)
13.以Stream Classes 完成輸入輸出
14.國際化(Internationalization,i18n)
15.空間配置器(Allocator)
網絡上的資源
參考書目
索引

【14 國際化】

47.11德國人寫成47,11,一百萬尼泊爾人寫成10.00.000,這涉及國際化:語言.地區.編碼
(1)cin.imbue(locale::classic());將C local賦給cin
(2)locale loc("")//得到環境local
(3)P700改動全局local,將影響C函數,和新建對象,不能影響已經創建的cin之流
(4)用cin.getloc()得到的locale對象,可以用於全局函數P719,進行基本測試。直接用facet函數更快


【11 string專題】
例子:改後綴、逆向單詞、P497大小寫轉換忽略,reverse,sort,unique,uniquecopy,isspace

  1. string::npos只能與string::size_type比較。因爲前者不一定總是-1。
  2. string類似vector<char>,但前者以整個容器爲優化對象
  3. 源對象:string(允許中間一段:inx+len,或b+e)、char[](從頭指定一段,/0也是普通字符)、c-string(照單全收,遇/0自動結束)、單字符、若干字符。
  4. swap()常速速度取代'='!c-string含/0,string不含,數組視/0普通!at()取值優先使用[]!"aa"是c-string,也是字符數組。
  5. max_size()指理論容量,capacity()指當前容量,size()=length()指字符個數,reserve()調整容量(強擴弱縮),resize()強制擴充字符,erase()包含clear()的全刪功能
  6. assign()就是'=',append()就是'+=',pushback('c')爲STL算法,就是無r的append('c'),insert(),replace()
  7. find(),efind()找字串,find_first/last_of(),find_first/last_not_of(),找字符
  8. substr()可以返回副本!,getline()從istream中一直讀直到(/n,delim)
  9. 空串的end()/rend()就是begin()/rbegin(),+,<<,>>,allocator_type,get_allocator()
  10. comparison()像全局函數比較2個外串,compare比較自己,_c_str(),data()返回內部數據,copy()賦值到buf
  11. 字典順序比較就是:按ascii逐一比較直到比出勝負,多爲大。
  12. 用s.insert((std::string::size_type)0,1,' ')避免insert(0,1' ')歧義
  13. 不要用null代替char*,

【13 stream】

  1.  主要istream、ostream管讀寫
  2. 4個全局stream對象:cin、cout、cerr、clog
  3. ofstream(c_str)、?file、file<<、自動管理文件關閉。

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章