Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #define INPUT_FILE "input.txt"
- #define OUTPUT_FILE "output.txt"
- using namespace std;
- int main () {
- bool end = false;
- int N;
- double somma;
- fstream infile, outfile;
- infile.open(INPUT_FILE, fstream::in);
- outfile.open(OUTPUT_FILE, fstream::out);
- if(!infile.is_open()) {
- cerr << "Error opening file " << INPUT_FILE << endl;
- return -1;
- }
- if(!outfile.is_open()) {
- cerr << "Error opening file " << OUTPUT_FILE << endl;
- return -1;
- }
- while (!end) {
- infile >> N;
- if (infile.eof()) {
- cout << "end of input, exit!" << endl;
- end = true;
- }
- else if(infile.fail()) {
- cerr << "Error reading N from file " << INPUT_FILE << endl;
- end = true;
- }
- }
- infile.close();
- outfile.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement