请问C++中当文件指针到达末尾时如何重新回到开头?seekg(0),seekg(ios::beg)等都没效果,代码如下:
template<typename T>
void input(const char* fname, vector<T> &a)
{
ifstream ifile(fname);
int count(0), i(0);
T tmp;
while (!ifile.eof())
{
ifile >> tmp;
count ++;
}
a.resize(count);
ifile.seekg(ios::beg);//写了这个也还是回不去
while (!ifile.eof())
ifile >> a[i++];
ifile.close();
}
请各位高手指教!