Vectors are much like arrays, but they vary in size.
/*
* Read some integers into an vector, then echo them.
*/
#include <iostream>
#include <vector>
int main()
{
// Read them in.
std::vector<int> vec;
std::cout << "Enter some integers: " << std::endl;
int val;
while(std::cin >> val) {
vec.push_back(val);
}
// Print them back out again.
std::cout << "===============" << std::endl;
for(int sub = 0; sub < vec.size(); ++sub)
std::cout << vec[sub] << " ";
std::cout << std::endl;
}
Textbook: pp. 362—371
[more info]