BlueX

[C++]: Check Files.

Aug 1st, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main(){
  7.  
  8.     ifstream myfile;
  9.     double x;
  10.     double sum = 0;
  11.     char filename[50];
  12.  
  13.     cout <<"Enter the file name: ";
  14.     cin.getline(filename,50);
  15.  
  16.     myfile.open(filename);
  17.  
  18.     if(myfile.is_open()){
  19.  
  20.         while(myfile >> x){
  21.  
  22.             cout << x << endl;
  23.             sum += x;
  24.         }
  25.         cout << "result: " << x << endl;  
  26.     } else cout << "Error ocoured" << endl;
  27.  
  28.     system("PAUSE");
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment