Mega Code Archive

 
Categories / C++ Tutorial / File Stream
 

Read a file in try catch block

#include <fstream> #include <iostream> using namespace std; int main ()  {   try{       char buffer[256];       ifstream myfile ("test.txt");       while (! myfile.eof() )       {         myfile.getline (buffer,100);         cout << buffer << endl;       }   }catch(...){      cout << "There was an error !\n";   }   return 0; } This outputting a line.