原创 C++Primer課後題10.14、10.20、11.7

//習題10.14 void output_words(vector<string> &words) { for (auto i : words) { cout << i << " "; }

原创 c++Primer 5th課後題9.34、9.43、9.47、9.45、9.49

//命令行打開.exe時文件應與exe同目錄,ctrl+f5運行時文件應在main.c同目錄 //習題9.34 int main() { vector<int> vi = { 1,2,3,4,5,6,7,8 ,9 };

原创 C++primer5th 課後題13.58

習題13.58 class Foo { public: Foo sorted() && ; Foo sorted() const &; private: vector<int> data; }; Foo F

原创 C++primer5th模擬vector之StrVec類

出現的問題:書中alloc爲static,編譯時連接錯誤,不使用static可正常運行。因爲在c++11中,static必須要初始化 //現有知識儲備不知道怎麼給alloc初始化,所以……暫時去掉static StrVec.h頭

原创 C++Primer課後題11.33_單詞本程序

給定一string,轉換爲另一個string。輸入兩個文件,文件1爲替換規則,文件2爲文本 *map<string, string> buildMap(ifstream &map_file) //將轉換規則 創建爲trans_m

原创 C++primer5th課後題12.6、12.14、12.19

//習題12.6 //返回動態分配的int的vector,傳遞給另一個函數,讀取標準輸入保存爲vector元素中, /*shared_ptr<vector<int>> new_factor(void) { return m

原创 string的插入與刪除insert、erase

一、string 的 insert: s.insert(p,t);————— p迭代器,t值,插入在p之前,返回新元素的迭代器 s.insert(p,n,t); ———— n個值爲t元素,返回新添

原创 class 與 struct的區別

學C語言時,用struct來定義結構體,後來學C++的類,有時用struct有時用class,總會以爲它們兩個有很大的差別。 事實上在C++Primer 5th中文版p546中明確地指出了,class與struct在定義類時 唯

原创 C++Primer5th課後題10.11、10.13

//習題10.11 inline void output_words(vector<string> &words) { for (auto i : words) { cout << i << " ";

原创 C++primer5th十四章_幾個類的運算符重載

class Cdate { friend bool operator>(const Cdate &d1, const Cdate &d2); friend bool operator<(const Cdate &d

原创 C++模板中class與typename

在函數模板中,模板類型參數前必須要用關鍵字class或typename。 C++ Primer 5th一書中明確指出(p580): 在函數模板參數列表中,這兩個關鍵字的含義相同,可以互換使用。 一個模板參數列表中可以同時使用

原创 C++primer5th課後題13章13.13、13.22、13.26、13.27

習題13.13 class Employee { static int sn; string name; int mysn; public: Employee() { mysn = sn++; }

原创 C++primer5th課後題14.44,二元處理運算

習題14.44 簡單桌面計算器,處理二元運算 map<string, function<int (int, int)>> binOps = { {"+",plus<int>()},//標準庫函數對象 {"-",mi

原创 C++Primer課後題11.0、11.31

//習題11.9 string &trans(string &s) { for (int p = 0; p < s.size(); p++) { if (s[p] > 'A' && s[p] < 'Z')

原创 C++Primer5th課後題9.51_日期類

頭文件data.h的內容爲: #pragma once #ifndef DATE_H_INCLUDED #define DATE_H_INCLUDED #include<iostream> #include<string> #in