getline

C++ Reference

getline
Syntax:
  #include <string>
  istream& getline( istream& is, string& s, char delimiter = '\n' );

The C++ string class defines the global function getline() to read strings from and I/O stream. The getline() function, which is not part of the string class, reads a line from is and stores it into s. If a character delimiter is specified, then getline() will use delimiter to decide when to stop reading data.

For example, the following code reads a line of text from STDIN and displays it to STDOUT:

 string s;
 getline( cin, s );
 cout << "You entered " << s << endl;               
Related topics: