tellg在文件中执行写入操作后移动
tellg moves after write operation in file
为什么tellg()在写操作之后移动,我想它应该是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();
输出:
5
流实际上只维护一个指针,因此读指针和写指针实际上是相同的。如果要对同一个文件进行读写操作,则应维护自己的指针,并在每次读写操作之前进行查找。
相关文章:
- 复制和交换习惯用法与移动操作之间的交互
- 隐式移动与复制操作和遏制
- 我什么时候会默认(而不是删除)基类中的复制和移动操作
- 这将执行默认移动操作吗?
- 如何对移动操作进行单元测试(默认)?
- 我是否缺少<实验/文件系统>移动操作?
- 在理解移动语义的同时混淆 c++ 程序中的操作
- 我的移动分配操作程序重载的分段错误
- 是否有可能具有放入容器的移动操作的类型?
- 发送到另一个窗口的鼠标移动消息不执行任何操作
- 我什么时候需要移动操作,c++
- 在'string=string+s1'和"string+=s1"之间移动语义可以保存多少个复制操作?
- 变量可以通过C / C 的左或右移动操作变为null
- 标准::atomic_应该如何...<std::shared_ptr>用于线程安全类的复制和移动操作?
- 命令模式:如何进行连续操作?(例如,移动对象)
- 为什么C++允许您移动包含已删除移动操作的对象的类
- "pair::operator=(pair&&)"错误,"auto&"推断出移动操作 - libstdc++ 回归?
- 移动对象后支持哪些操作?
- 具有可以引发的移动操作的仅移动类的示例是什么?
- Visual Studio 2012 是否正确执行此操作?标准::移动