C++ examples for STL:vector
Create vector of int and add value to the vector
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main()//from ww w . j a va2 s .c om { const int NUMELS = 4; int n[] = {136, 122, 109, 146}; int i; vector<int> partnums(n, n + NUMELS); cout << endl; for (i = 0; i < int(partnums.size()); i++) cout << partnums[i] << " "; cout << endl; partnums[3] = 144; for (i = 0; i < int(partnums.size()); i++) cout << partnums[i] << " "; cout << endl; partnums.insert(partnums.begin()+1, 142); for (i = 0; i < int(partnums.size()); i++) cout << partnums[i] << " "; cout << endl; partnums.push_back(157); for (i = 0; i < int(partnums.size()); i++) cout << partnums[i] << " "; cout << endl; sort(partnums.begin(), partnums.end()); for (i = 0; i < int(partnums.size()); i++) cout << partnums[i] << " "; cout << endl; return 0; }