2012年(158)
分类: C/C++
2012-11-23 15:55:56
#include
#include
using namespace
std;
int main()
{
fstream f("a.txt",ios::out|ios::in|ios::trunc);
f << "abcdefg\n"; // f << "abcdefg"; 就是多了个\n,所以来问题了
f.seekg(0);
char ch;
cout << "tellg=" << f.tellg() <<
endl;
f >> ch;
cout << ch << endl;
cout
<< "tellg=" << f.tellg() << endl;
f >> ch;
cout << ch << endl;
cout << "tellg=" << f.tellg()
<< endl;
system("pause");
return
EXIT_SUCCESS;
}
输出为
tellg=0
a
tellg=2
c
tellg=4
而不是
tellg=0
a
tellg=1
b
tellg=2
------
2007-05-14:经 提醒,此帖重复,原帖为 http://blog.vckbase.com/bruceteen/archive/2006/03/27/18761.html