Getline function

What's the difference between getline(cin,name) and
cin.getline(name,100) are they not the same thing?
You use getline(cin, name) when name is a std::string:
1
2
string name;
getline(cin, name);

and cin.getline(name, 100) when name is a char array (a "C string", as they call it):
1
2
char name[100];
cin.getline(name, 100);

So the difference is the type of name.
Also on windows I think cin.getline() will leave the newline in the buffer. I could be wrong though.

Whoops I mean if you use cin >> then cin.getline() it will cause problems because the cin >> leaves the newline in the buffer and cin.getline() reads until the newline is found so it will not read anything. You must put a cin.ignore in there
Last edited on
Topic archived. No new replies allowed.