seekp()和seekg()执行相同的功能吗?

时间:2015-03-10 10:43:15

标签: c++

所以我知道使用seekp()来改变写入位置,而seekg()用于改变读取位置,但是当我在处理fstream对象时使用其中任何一个时,它会改变读写位置。 / p>

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
 fstream file("input.txt",fstream::in|fstream::out);
file.seekp(0,fstream::end);
file.seekg(0,fstream::beg);
cout << file.tellp() << " " << file.tellg() << endl;
}

此代码的输出为“0 0”。那么为什么会这样呢?

0 个答案:

没有答案