Gerard-Meier

basic readfile

Feb 19th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. int main()
  5. {
  6.    
  7.     std::stringstream data;
  8.     int x;
  9.     ifstream inFile;
  10.    
  11.     inFile.open("C:\\Users\\G. Meier\\Documents\\myfile.txt");
  12.     if (!inFile) {
  13.         cout << "Unable to open file";
  14.         exit(1); // terminate with error
  15.     }
  16.    
  17.     char c;
  18.     while (inFile.get(c)) {
  19.         data << c;
  20.     }
  21.    
  22.     inFile.close();
  23.     cout << "data = " << data.str() << endl;
  24.     return cin.get();
  25. }
Advertisement
Add Comment
Please, Sign In to add comment