Advertisement
bruimafia

Untitled

May 18th, 2021
777
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. void arrayOutput(int sizeArray, int* array, ifstream& file) {
  7.     for (int i = 0; i < sizeArray; i++) {
  8.         file >> array[i];
  9.         cout << array[i] << endl;
  10.     }
  11. }
  12.  
  13. int main(int argc, const char * argv[]) {
  14.    
  15.     ifstream file("text.txt");
  16.    
  17.     int array1[2], array2[4];
  18.    
  19.     if (!file) {
  20.         cout << "error" << endl;
  21.         return 0;
  22.     }
  23.    
  24.     cout << "first array" << endl;
  25.     arrayOutput(2, array1, file);
  26.     cout << "second array" << endl;
  27.     arrayOutput(4, array2, file);
  28.    
  29.     file.close();
  30.     return 0;
  31. }
  32.  
  33.  
  34. // СОДЕРЖИМОЕ ФАЙЛА "text.txt":
  35. /*
  36.  4
  37.  3
  38.  7
  39.  9
  40.  5
  41.  6
  42.  */
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement