Sinux1

PS5Q10 cs 111

Mar 11th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream> // ifstream, open, eof, close
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8.     ifstream data_store;
  9.     string line, filename;
  10.     int x = 1;
  11.    cout << "Enter filename\n";
  12.    cin >> filename;
  13.  
  14.    data_store.open(filename.c_str());
  15.  
  16.     if (!data_store)
  17.     {
  18.         cout << "File not found" << endl;
  19.         return 0;
  20.     }
  21.     while (!data_store.eof())
  22.     {
  23.  
  24.         getline(data_store, line);
  25.         cout << x << ": " << line << endl;
  26.         x ++;
  27.     }
  28.     //step 4
  29.     data_store.close();
  30.  
  31.  
  32.     return 0;
  33. }
Add Comment
Please, Sign In to add comment