Question: I was working on a school project with my friend and we want our program to take integer values from user and store it in a vector as long as the user enter some value and exit the loop for input when user stops inputting numbers.

This was my first sample code which goes on infinitely:

```
while(cin>>x){
                v.push_back(x);
        }

```

There is a condition that the numbers must be greater than one but enter is greater than 0 in integer value so my second code is but it is not working and it also goes on infinitely.

This is my sample code:

```
while(cin>>x){
            if(x<0){
                break;
            }
            else{
                v.push_back(x);
            }
        }

```

Kindly suggest me a solution thanks in advance :)

Answer: 
Most important part for you is to clearly describe what you want. The program has to have some condition under which it terminates.

Two ideas:

1. The user enters integer values separated by spaces and then pushes enter
2. The user enters an integer, presses enter and continues. As soon as he presses enter twice, it terminates.

How to do it:

1. Simple use cin with a string, delimit by space and then convert to integers.
2. Use cin with a string but otherwise as you do right now, ask whether the string is "", if not convert to integer.
After using [Aziuth's](https://stackoverflow.com/users/5114342/aziuth)  suggestion and doing some research on websites like Topcoder and Codechef and other competitive programming websites I think i found a solution without needing to use a string. It takes all the input values until a newline is entered. Thanks a lot everyone for their time and knowledge for this question.

The code is:

```
while(1){
            cin>>x;
            v.push_back(x);
            char ch = getchar();
            if(ch=='\n')
                break;
        }

```