Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. int main ( )
  7. {
  8.     ifstream file ( "test.txt" );
  9.     string line;
  10.     try
  11.     {
  12.         if ( file.fail ( ) )
  13.         {
  14.             throw (string) "unable to open the file\n";
  15.         }
  16.         while ( getline ( file , line ) )
  17.         {
  18.             cout << line << '\n';
  19.         }
  20.         file.close ( );
  21.     }
  22.     catch ( string error )
  23.     {
  24.         cout << error << '\n';
  25.     }
  26.    
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement