Created
August 29, 2019 21:59
-
-
Save aqd14/1eae7f3af4e8008c78b81a18b8c5d451 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Defining and initializing vectors | |
vector<T> v1; // vector that holds object of type T, default constructor v1 is empty | |
vector<T> v2 (v1); // v2 is a copy of v1 | |
vector<T> v3(n, i); // v2 has n elements with value i | |
vector<T> v4(n); // v4 has n copies of a value-initialized object | |
# The size of a vector | |
vector<int>::size_type | |
vector<int> v; | |
for (vector<int>::size_type ix = 0; ix != 10; ++ix) { | |
// v[ix] = ix; // wrong | |
v.push_back(ix); | |
} | |
# Iterator | |
vector<int> v(10, 1); | |
for (vector<int>::iterator iter = v.begin(); iter != v.end(); ++iter) { | |
cout << *iter << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment