Read a line of text into string with getline function - C++ STL

C++ examples for STL:string

Description

Read a line of text into string with getline function

Demo Code

#include <iostream>
#include <string>
using namespace std;
int main()//from w w w.  j  a v a  2 s  .  co  m
{
   string message;     // declare a string object
   cout << "Enter a string:\n";
   getline(cin, message);
   cout << "The string just entered is:\n" << message << endl;
   return 0;
}

Result


Related Tutorials