Skip to content

Instantly share code, notes, and snippets.

@aqd14
Created August 29, 2019 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aqd14/1eae7f3af4e8008c78b81a18b8c5d451 to your computer and use it in GitHub Desktop.
Save aqd14/1eae7f3af4e8008c78b81a18b8c5d451 to your computer and use it in GitHub Desktop.
# 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