Reputation: 191
Why does tellg() moves after a write operation, I suppose it should be tellp()?
std::fstream fs("c:\\log.txt", std::ios::in | std::ios::out | std::ios::trunc);
fs << "write";
std::cout << fs.tellg() << std::endl;
fs.close();
Output:
5
Upvotes: 0
Views: 331
Reputation:
The stream actually maintains only one pointer, so the read and write pointers are effectively the same. if you want to do reads and writes to the same file, you should maintain your own pointer and do a seek before every read/write operation.
Upvotes: 2