Jump to content

C++ Read File Content

- - - - -

  • Please log in to reply
No replies to this topic

#1
QuackWare

QuackWare

    Learning Programmer

  • Members
  • PipPipPip
  • 95 posts
C++ Read File Content



/** This code snippet was taken from freecodesnippets.com*/



 

#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;

}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users