Mega Code Archive

 
Categories / C++ Tutorial / File Stream
 

Open a file for input and read in its content

#include <fstream> #include <iostream> using namespace std;     int main ()  {   char buffer[256];     fstream myfile;   // open it for input and read in   myfile.open("test.txt",ios::in);   myfile.getline(buffer,100);   cout << "The file contains   " << buffer << "\n";   myfile.close();     return 0; } The file contains This outputting a line.