getline()

What's the difference between:
std::getline(std::cin, string, '\n');

And:
std::cin.getline(string, '\n');
std::cin.getline(string, '\n');
This version is incorrect. Its this:
std::cin.getline(char_array_ptr, 50);

Difference is that the std::getline is built for the STD string library and handles them by getting the line from the istream defined in argument 1, and places the characters into the std::string argument 2. The third argument is the character that std::getline stops reading input into the std::string.

The second is built for character arrays otherwise know as C-Strings. Th first argument is the pointer to the array to fill and the second argument is the max size of the buffer than can be filled. This was made to replace the older stdio methods which had exploitable holes in their design such as buffer overflow. This guy also takes a third argument which is the same as above, and changes the delimiter character of the input.
Topic archived. No new replies allowed.