关于fstream中的指针移动的有关问题
关于fstream中的指针移动的问题
先贴一段程序:
#include <iostream>
#include <fstream>
using namespace std;
void main()
{
fstream fs( "a.txt ");
int n;
for(;fs> > n;)
{
}
fs.seekp(0,ios::beg);
fs> > n;
cout < <n;
}
a.txt保存内容为:
1
2
3
4
程序的运行结果是:4
不知道为什么希望高手能给个回答~万分感谢
------解决方案--------------------
fs.clear();
fs.seekp(0,ios::beg);
先贴一段程序:
#include <iostream>
#include <fstream>
using namespace std;
void main()
{
fstream fs( "a.txt ");
int n;
for(;fs> > n;)
{
}
fs.seekp(0,ios::beg);
fs> > n;
cout < <n;
}
a.txt保存内容为:
1
2
3
4
程序的运行结果是:4
不知道为什么希望高手能给个回答~万分感谢
------解决方案--------------------
fs.clear();
fs.seekp(0,ios::beg);