Use getline() to read a string that contains spaces. : File Read « File « C++






Use getline() to read a string that contains spaces.

Use getline() to read a string that contains spaces.
 

#include <iostream>
#include <fstream>
using namespace std;

int main()
{ 
  char str[80];

  cout << "Enter your name: ";
  cin.getline(str, 79);

  cout << str << '\n';

  return 0;
}


           
         
  








Related examples in the same category

1.Write char to a fileWrite char to a file
2.Read file contentRead file content
3.Demonstrate gcount().Demonstrate gcount().
4.Demonstrate peek() in ifstreamDemonstrate peek() in ifstream
5.Demonstrate seekg().
6.Read formatted data from a file.
7.Write unsigned char to a file and read it back