C++ ifstream Reads formatted text file via >>

Description

C++ ifstream Reads formatted text file via >>

#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()//from www .  j a va 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;
}



PreviousNext

Related