# C++ Note ## I/O ### input ```cpp= cin >> "Hello chihuahua"; ``` ### output ```cpp= cout << "byebye chihuahua"; cout << "byebye" << endl; // next line ``` ## string ```cpp= #include <string> string s; ``` 輸入包含空白的整行文字,使用 getline() 以輸入 ``"Hello chihuahua!"`` 為例 ```cpp= cin >> s; cout << s; // Hello getline(cin, s); cout << s; // Hello chihuahua! ``` --- ## Vector ### create ```cpp= #include <vector> // vector<type> name; vector<int> num = {1, 2, 3}; ``` ### .push_back() To add a new element to the “back”, or end of the vector, we can use the `.push_back()` function. ```cpp= num.pushback(4); // 1, 2, 3, 4 ``` ### .pop_back() You can also remove elements from the “back” of the vector using `.pop_back()`. ```cpp= num.pop_back(); // 1, 2, 3 ``` ### .size() The `.size()` function returns the number of elements in the vector. ```cpp= num.size(); // 3 ```