Hey guys, I just wrote a simple program that takes 10 integers into a vector, and the goal of the program is to output the ten numbers, all multiplied by two, using iterators. Well, I wrote the code and it seems fine, and also compiles fine, but when I enter in the first ten numbers into the vector, it says "Project1.exe has stopped working..." I'm currently using Vista Home Basic. Can anyone tell me what's going on? Thanks for anything in advance.
Here's the code:
Code:
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> str(10);
int num, counter;
while (cin >> num){
str.push_back(num);
}
for (vector<int>::iterator iter = str.begin(); iter != str.end(); ++iter){
*iter = str[counter] * 2;
++counter;
cout << *iter << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}