Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- void save_file(int[], size_t);
- void read_file(int[], size_t);
- int main() {
- int a[] = { 1, 2, 3, 4, 5 };
- save_file(a, 5);
- read_file(a, 5);
- return 0;
- }
- void save_file(int array[], size_t array_size) {
- ofstream file;
- file.open("test.txt");
- for (size_t i = 0; i < array_size; i++)
- file << array[i];
- file.close();
- }
- void read_file(int array[], size_t array_size) {
- ifstream file;
- file.open("test.txt");
- if (file.is_open())
- for (size_t i = 0; i < array_size; i++) {
- file >> array[i];
- cout << array[i];
- }
- file.close();
- }
Add Comment
Please, Sign In to add comment