Advertisement
AlexandruFilipescu

C++ send numbers from a file to odd.txt and even.txt

Aug 6th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int main() {
  9.     int i;
  10.     ifstream f("numere.txt");
  11.     ofstream g("impare.txt");
  12.     ofstream g2("pare.txt");
  13.     int numar;
  14.  
  15.     while (f>>numar) {
  16.         if (numar%2==1) {
  17.             g << numar << " ";
  18.         } else {
  19.             g2 << numar << " ";
  20.         }
  21.     }
  22.     f.close();
  23.     g.close();
  24.     g2.close();
  25.  
  26.     system("pause");
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement