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;
- int y;
- 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;
- }
- else {
- int v[N];
- int i;
- for (i=0; i<N; i++) {
- infile >> y;
- if (y%2==1)
- v[i]=y;
- else
- infile.ignore();
- }
- for (i=0; i<N; i++) {
- if (!(outfile << v[i] << " ")) {
- cerr << "error writing number on file!" << endl;
- end = true;
- }
- }
- if (!(outfile << "\n")) {
- cerr << "error writing on file!" << endl;
- end = true;
- }
- }
- }
- infile.close();
- outfile.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement