Reads formatted output from a file, using >> - C++ File Stream

C++ examples for File Stream:stream

Description

Reads formatted output from a file, using >>

Demo Code

#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()/*from   w  w w  .j  a v  a 2  s  .  c o m*/
{
   char ch;
   int j;
   double d;
   string str1;
   string str2;
   ifstream infile("fdata.txt");   //create ifstream object extract (read) data from it
      infile >> ch >> j >> d >> str1 >> str2;
   cout << ch << endl
       << j << endl
       << d << endl
       << str1 << endl
       << str2 << endl;
   return 0;
}

Result


Related Tutorials