Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- /*
- std::ios::app -- append to file
- std::ios::in - open file for input, reading
- std::ios::out - open file for output, writeing
- std::ios:binary - opens file in binary mode
- std::ios::ate - opens file and moves file pointer to END, pr AT ehe End
- std::ios::trunc - removes file if exist
- */
- // iofile.seekg(iofile.tellg(), std::ios::beg)
- int main()
- {
- std::fstream iofile;
- iofile.open("test.txt", std::ios::in | std::ios::out); //| std::ios::ate
- //iofile.seekg(0, std::ios::end);
- //std::cout << "Current reading position: " << iofile.tellg() << '\n';
- //iofile.seekg(12, std::ios::beg);
- //std::cout << "First move Current reading position: " << iofile.tellg() << '\n';
- //iofile.seekg(-7, std::ios::cur);
- //std::cout << "Second move Current reading position: " << iofile.tellg() << '\n';
- char buf[100];
- char symbol{};
- while (iofile.get(symbol))
- {
- if (symbol == '#')
- {
- iofile.seekp(((int)iofile.tellg() - 1), std::ios::beg);
- iofile << 't';
- iofile.seekg(iofile.tellg(), std::ios::beg);
- }
- }
- //while (!iofile.eof())
- //{
- // iofile.getline(buf, 100);
- // std::cout << buf << '\n';
- // std::cout << "Current reading position: " << iofile.tellg() << '\n';
- //}
- std::cout << "Current reading position: " << iofile.tellg() << '\n';
- iofile.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement