Hi, i'm new to C++ and the book which i am reading says that the purpose of getline is to show the whole line. Could someone please elaborate on this.
Thanks
Hi, i'm new to C++ and the book which i am reading says that the purpose of getline is to show the whole line. Could someone please elaborate on this.
Thanks
Change "show" to "read" and it might make more sense to you.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
i still don't understand what it means... cant you read the whole line without getline?
Suppose you want the user to enter a line of text, e.g.,Originally Posted by Grae
You want to store the line read into a std::string object. You can thus write:Code:This is a line of text.
Upon which the string will contain "This is a line of text."Code:std::string line; std::getline(std::cout, line);
It is also possible to provide a third argument to getline to use a different delimiter, i.e., to read a "line" that stops when a character that you have in mind is read.
Yes, but getline makes it more convenient.Originally Posted by Grae
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
k thanks that makes much more sense, this has nothing to do with the previous question but how would u compare two strings to see which comes first, using an if statement and comparison operators?
You should start a new thread to ask a new question. But before you do that, read up more on how to use std::string objects.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)