Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 15.12.2016
- * Обработка динамического списка std::list
- * Запись и чтение его элементов в двоичный файл
- */
- #include <iostream>
- #include <list>
- #include <fstream>
- using namespace std;
- int main()
- {
- fstream bin("bin.txt", ios_base::binary | ios_base::out | ios_base::in | ios_base::app);
- int temp;
- list<int> l;
- cout << "Input numbers: ";
- while (cin >> temp)
- l.push_back(temp);
- for (list<int>::iterator i = l.begin(); i != l.end(); i++)
- {
- temp = *i;
- bin.write((char*)&temp, sizeof(int));
- }
- list<int> rl;
- bin.seekg(0, ios_base::beg);
- while (true)
- {
- bin.read((char*)&temp, sizeof(int));
- if (bin.eof()) break;
- rl.push_back(temp);
- }
- bin.close();
- cout << "List from binary file: ";
- for (list<int>::iterator i = rl.begin(); i != rl.end(); i++)
- cout << *i << ' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment