Read file content : File Read « File « C++






Read file content

Read file content
 
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
  ifstream in("test", ios::in | ios::binary);

  if(!in) {
    cout << "Cannot open input file.\n";
    return 1;
  }

  double num;
  char str[80];

  in.read((char *) &num, sizeof(double));
  in.read(str, 14);
  str[14] = '\0'; // null terminate str

  cout << num << ' ' << str;

  in.close();

  return 0;
}


           
         
  








Related examples in the same category

1.Write char to a fileWrite char to a file
2.Demonstrate gcount().Demonstrate gcount().
3.Use getline() to read a string that contains spaces.Use getline() to read a string that contains spaces.
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