原创 c++ primer(第五版)筆記 第九章 順序容器(2)

// 順序容器 // 添加元素(array 除外) // 在尾部創建一個值爲 t 或由 args 創建的元素,返回 void,不支持 forward_list // c.push_back(t) // c.emplace_back

原创 c++ primer(第五版)筆記 第三章(1)string類

//#define NDEBUG #include<iostream> #include<string> #include<cassert> //using namespace std; //using 聲明不應該出現在頭文件中,會使

原创 c++ primer(第五版)筆記 第九章 順序容器(1)

// 順序容器(sequential container) // vector 可變大小數組,快速隨機訪問,在尾部之外的位置插入或刪除元素可能很慢 // deque 雙端隊列,快速隨機訪問,在頭尾快速插入或刪除 // list 雙向

原创 c++ primer(第五版)筆記 第四章 表達式

#include<iostream> #include<vector> #include<string> #include<cstddef> using std::cout; using std::cin; using std::end

原创 makefile 簡介

1.簡單的命令格式target : prerequisitesrecipetarget 通常是一個程序生出的文件名,比如對象文件(.o),也可能是一

原创 c++ primer(第五版)筆記 第六章 函數(2)

#ifndef FUNC_H #define FUNC_H #include<iostream> #include<string> #include<vector> #include<cstdlib> using std::cout;

原创 譯自five popular myths about c++ --by Bjarne Stroustrup (4)

 Myth 4: "For efficiency, you must write low-level code" 爲了效率,你必須編寫底層代碼 Many people seem to believe that efficient c

原创 Data Structures and Algorithm Analysis in c++ 第一章筆記和部分習題

注:輸入問題懶得搞,  A<X> 表示A的X次方  logA(B) 表示底數爲A,真數爲B  加減乘除等 +-*/=   指數 exponent  A<X> * A<Y> = A<X + Y>  A<X> / A<Y> = A<X -

原创 譯自five popular myths about c++ --by Bjarne Stroustrup (2)

Myth 2: "C++ is an Object-Oriented Language"c++ 是面向對象的語言 No. C++ supports OOP and other programming s

原创 c++ primer(第五版)筆記 第十二章 動態內存(2)

// 動態數組 #inlcude <memory> #inlcude <string> int main(){ // 分配要求數量的對象,返回第一個對象的指針 // []內必須是整型,不要求常量 // ()內爲初始化值 int

原创 c++ primer(第五版)筆記 第十四章 重載運算與類型轉換

// 重載運算符: 其函數名由operator關鍵字和定義的運算符號組成 // 其參數數量與該運算符作用的運算對象數量一致 // 對於二元運算符來說,左側運算對象傳遞給第一個參數,右側運算對象傳遞給第二個參數 // 除 operator(

原创 譯自five popular myths about c++ --by Bjarne Stroustrup (5)

 Myth 5: "C++ is for large, complicated, programs only" c++ 只是用於大型複雜的程序 C++ is a big language. The size of its defin

原创 c++ primer(第五版)筆記 第十二章 動態內存(1)

// 靜態內存(static) 局部static, 類static, 定義在任何函數之外的變量,由編譯器自動創建和銷燬,程序使用前創建,程序結束時銷燬, // 棧(stack) 函數內的非static 對象,由編譯器自動創建和銷燬,僅在

原创 譯自five popular myths about c++ --by Bjarne Stroustrup (3)

Myth 3: "For reliable software, you need Garbage Collection" 作爲可以信賴的軟件,垃圾回收機制不可少 Garbage collection does a good, but n

原创 c++ primer(第五版)筆記 第九章 順序容器(3)

// 容量管理 // 將 capacity 減少到和 size() 相同 // 用於 vector string deque // 不一定執行 // c.shrink_to_fit() // 不重新分配內存的話,c 可以保存