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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.