string.getline() doesn't work

I wrote:

1
2
string test;
getline(cin, test);


I should be able to put into the string "test" a whole line of input, am I right?

However, it doesn't even starts the input... Any help?
There is nothing wrong with the snippet you posted. You need to provide more content.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
string test;
        
cout << "Insert string" << endl;
        
while (1) {
            
    getline(cin, test);
            
    if (test == "stop") {
        break;
    }
            
    /*...*/
}
        
/*...*/


This is my real code, sorry. Well, it doesn't start the input.
Can you post the output you get when you compile it?
The output is only the "cout" output.

Insert string:
Remember you need to press [enter] after you have completed your input.

I've a feeling you wanted the input to be recognised as completed when you press some other key. If that's what you want, you'd need to monitor individual keystrokes, instead of simply using cin.
fpiro i tried your code in VS2012 and it works perfectly.
Still the same problem. I mixed up the extraction operator ">>" with the getline function. Solved! √
Topic archived. No new replies allowed.