Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- int main()
- {
- std::fstream file;
- file.open("file.txt", std::ios::in | std::ios::out | std::ios::trunc);
- if (!file) { std::cout << "IOERROR!\n"; return 1; }
- for (int i{ 0 }; i < 10; ++i)
- {
- file << (1000 + rand() % 1000) << '\n';
- }
- file.seekg(0, std::ios::beg);
- char str[20];
- while (!file.eof())
- {
- file.getline(str, 19);
- std::cout << str << '\n';
- }
- file.clear();
- file.seekg(0, std::ios::beg);
- char symb{};
- while (!file.eof())
- {
- file.get(symb);
- if (symb == '1')
- {
- file.seekp(-1, std::ios::cur);
- file << '9';
- file.seekg(file.tellp(), std::ios::beg);
- }
- }
- file.clear();
- file.seekg(0, std::ios::beg);
- while (!file.eof())
- {
- file.getline(str, 19);
- std::cout << str << '\n';
- }
- file.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement