Vector input
Jun 5, 2013 at 5:15pm UTC
Hi!
I would like to input 10 numbers to my vector. I am having a bit of tough luck though. Would someone direct me into the right direction?
My code:
1 2 3 4 5 6
int input;
vector<int > v;
while (cin >> input)
v.push_back(input);
for (int i=0; i<v.size(); i++)
cout << v[i] << endl;
I would need to input 10 integers, and display them. Is my code above are getting 'started'? Thanks.
Jun 5, 2013 at 5:21pm UTC
Input 10 numbers, then press Ctrl+Z (or type a word) and hit enter. Does it work? Right now you have it set to input infinite numbers until end of input or something that isn't a number.
Jun 5, 2013 at 5:28pm UTC
>>L B
Do you have any suggestions about the code? I tried:
1 2 3
for (int i=0; i<10; i++)
cin >> input;
v.push_back(input);
Jun 5, 2013 at 5:32pm UTC
1 2 3 4 5
for (int i=0; i<10; i++)
{
cin >> input;
v.push_back(input);
}
Otherwise what you have written is the same as:
1 2 3 4
for (int i=0; i<10; i++)
cin >> input;
v.push_back(input);
Jun 5, 2013 at 5:33pm UTC
>>L B
Got it thanks!
Topic archived. No new replies allowed.