How to terminate input and go directly to output?

hey guys,

I'm almost done with my program but I have one problem...

I can't terminate my input the correct way and go to the output.
My input is
string w;
getline(cin, w);
and when the user inputs " @@@ " and then enter, it's supposed to terminate.


Any ideas how to do that? Or do I need to change my input form to cin?
You just have to test your string variable, "w" in this case, for the " @@@ " value. If it matches then you break the loop. Personally I'd use a do while(...) loop for this.
I do. and I do have a do while loop.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
do {
int bindex = 0, eindex = 0, i = 0, wlen = 0;
getline (cin,w);
toLowerCase(w);
removePunct(w, i);
for (i = bindex; i < w.length(); i++){
    if (w[i] == ' '){
    w2 = w.substr(bindex, wlen );
    bindex = i+1;
    wlen = 0;
    count++;
    find.search(w2, count, found);  
}
else wlen++;
}}    
while (w.compare("@@@") != 0);


Just pretend those have variable declarations already. ..
I input @@@ at the end but Ii'm thinking since it's getline, it won't notice the @@@?
Because when I put @@@ by itself on a new line, it will terminate. Other than that, it won't terminate when it's on the same line as my other input
Right it has to be an exact match for the "compare(...)" string member function to return 0. If you are trying to test for "@@@" INSIDE of the target string you could use the "search(...)" STL member function: http://www.cplusplus.com/reference/algorithm/search/
Alright, thanks I'll look into it!
Topic archived. No new replies allowed.