Advertisement
Guest User

Untitled

a guest
Oct 7th, 2019
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4.  
  5. #define INPUT_FILE "input.txt"
  6. #define OUTPUT_FILE "output.txt"
  7.  
  8. using namespace std;
  9.  
  10. int main () {
  11. bool end = false;
  12.  
  13. int N;
  14. double somma;
  15.  
  16. fstream infile, outfile;
  17.  
  18. infile.open(INPUT_FILE, fstream::in);
  19. outfile.open(OUTPUT_FILE, fstream::out);
  20.  
  21. if(!infile.is_open()) {
  22. cerr << "Error opening file " << INPUT_FILE << endl;
  23. return -1;
  24. }
  25.  
  26. if(!outfile.is_open()) {
  27. cerr << "Error opening file " << OUTPUT_FILE << endl;
  28. return -1;
  29. }
  30.  
  31. while (!end) {
  32.  
  33. infile >> N;
  34.  
  35. if (infile.eof()) {
  36. cout << "end of input, exit!" << endl;
  37. end = true;
  38. }
  39.  
  40. else if(infile.fail()) {
  41. cerr << "Error reading N from file " << INPUT_FILE << endl;
  42. end = true;
  43. }
  44.  
  45.  
  46.  
  47. }
  48.  
  49.  
  50. infile.close();
  51. outfile.close();
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement