C++ Quick Guide
https://www.tutorialspoint.com/cplusplus/cpp_quick_guide.htm
Compiled Support
sudo vim ~/.bashrc
# alias for g++ support C++ standard 11, 14, 17, 20
alias g++11='g++ -std=c++11'
alias g++14='g++ -std=c++14'
alias g++17='g++ -std=c++17'
alias g++20='g++ -std=c++2a'
sudo source .bashrc
a simple example
#include <iostream> #include <vector> using namespace std; int main() { // create a vector to store int vector<int> vec; int i; // display the original size of vec cout << "vector size = " << vec.size() << endl; // push 5 values into the vector for(i = 0; i < 5; i++) { vec.push_back(i); } // display extended size of vec cout << "extended vector size = " << vec.size() << endl; // access 5 values from the vector for(i = 0; i < 5; i++) { cout << "value of vec [" << i << "] = " << vec[i] << endl; } // use iterator to access the values vector<int>::iterator v = vec.begin(); while( v != vec.end()) { cout << "value of v = " << *v << endl; v++; } return 0; }
g++ -o mian main.cpp -std=c++11
g++11 -o mian main.cpp
g++14 -o mian main.cpp
g++17 -o mian main.cpp
g++20 -o mian main.cpp
C++ STL
Containers
1. vector
https://docs.microsoft.com/en-us/cpp/standard-library/vector-class?view=vs-2019
2. stack
https://docs.microsoft.com/en-us/cpp/standard-library/stack-class?view=vs-2019
3. list
https://docs.microsoft.com/en-us/cpp/standard-library/list-class?view=vs-2019
4.queue
https://docs.microsoft.com/en-us/cpp/standard-library/queue-class?view=vs-2019
Algorithms
Iterators
std::find和std::find_ if