
【C++】 文件指针回到开头
请问C++中当文件指针到达末尾时如何重新回到开头?seekg(0),seekg(ios::beg)等都没效果,代码如下:template<typenameT>voidin...
请问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();
}
请各位高手指教! 展开
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();
}
请各位高手指教! 展开
6个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询