What type of variable is input? if it is a number of some kind then just entering a character should stop the first loop. But you should be able to force eof() by entering either Ctrl-D or Ctrl-Z (on a line by it's self), which key combination depends upon your operating system..
>> is an operator that returns the cin object. The loop continues until cin fails to read whatever data type input is. So, if you type in a number, hit enter, repeat, or type in a set of numbers (1 2 3 4) and then hit enter, the cin object is still okay.
You could end your first piece of code with the following: (assuming input is a number type)
1 2 3 4 a
>> reads until it hits the "a", at which point cin is broken, thus ending the loop.
Not a very good solution though.
You can use peek() to help you if you are typing in a set of numbers:
1 2 3 4 5
while (cin.peek() != '\n')
{
cin >> temp;
v.push_back(temp);
}
If you don't want to do that, you can use a sentinal:
1 2 3 4
cout << "Enter numbers, negative to stop";
int temp;
while (cin >> temp && temp >= 0) // For your use, zero seems a better sentinal than negative
v.push_back(temp);