end a while statement by cin>> empty line

for the program i am currently working on, i a situation similar to this:

1
2
3
4
string word;
cin word 
while (word!="enter nothing")
{cin word;}



if that makes sense. basically i need to exit the while statement by entering in nothing when it asks me to input word. how would you do that? ive tried while (word!="") and while (word!=null) but all it does when i hit enter is continue waiting for me to input something
thanks!
Try while(cin>>word) {}
still no luck.

heres the loop
1
2
3
4
5
6
7
8
9
10
11
............
 cout<<"Enter a word that you would like to claim (000 to end)"<<endl;
        cin>>claimed;
         int counter=0;
    findwords ();
       while (claimed!="000"){  //loops claimed words search until you type 000
            found=0;

...........................

cin>>claimed; }

...............
and i wanna change it to this:
1
2
3
4
5
6
7
8
9
10
11
12
 cout<<"Enter a word that you would like to claim (000 to end)"<<endl;
      //cin>>claimed   ***tried it both with and without this here**
         int counter=0;
    findwords ();
       while (cin>>claimed){  //loops claimed words search until you type 000
            found=0;

.................
cin>>claimed;

}



any idea what i did wrong there?
Well that while loop will continue looping until you enter bad data, which is what I thought you wanted to do. If you want to do it that way, you will have to check the string the way you were originally, just use getline() instead of cin>> to get into the string.
i wanna end the loop when i enter in nothing, just press enter to continue, instead of having to type in the 000 in the example above.

where would i put the getline?
do you mean like

while (getline (claimed))?

or do you mean instead of asking the user for the word? i dint think getline could be used that way.
thanks for the help =]
Instead of cin>>claimed, use getline(cin, claimed).

Then check if claimed == "" instead of "000" or whatever.
when i replace cin>>claimed with getline (cin, claimed); it just skips over it, never asks me to cin>> anything.. any advice on what im doin wrong?
In your OP what happens when you implement Zhuge's proposal ?(after deleting lines 2 and 4)
Topic archived. No new replies allowed.