Garey

File opened

Dec 21st, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. void save_file(int[], size_t);
  7. void read_file(int[], size_t);
  8.  
  9. int main() {
  10.  
  11.     int a[] = { 1, 2, 3, 4, 5 };
  12.  
  13.     save_file(a, 5);
  14.  
  15.     read_file(a, 5);
  16.  
  17.     return 0;
  18. }
  19.  
  20. void save_file(int array[], size_t array_size) {
  21.     ofstream file;
  22.     file.open("test.txt");
  23.    
  24.     for (size_t i = 0; i < array_size; i++)
  25.         file << array[i];
  26.  
  27.     file.close();
  28. }
  29.  
  30. void read_file(int array[], size_t array_size) {
  31.     ifstream file;
  32.  
  33.     file.open("test.txt");
  34.  
  35.     if (file.is_open())
  36.         for (size_t i = 0; i < array_size; i++) {
  37.             file >> array[i];
  38.             cout << array[i];
  39.         }
  40.  
  41.     file.close();
  42. }
Add Comment
Please, Sign In to add comment