|
我想用inFile.seekg(0,ios:beg)让文件指针指向文件的开头,好像没有起作用
- #include<iostream>
- #include<fstream>
- #include<iomanip>
- using namespace std;
- int main()
- {
- int i=0;
- int j=0;
- long Primes,Primes_1;
- char* filename="/C++/file/primes";
- ifstream inFile(filename,ios::in|ios::binary);
- if(!inFile)
- cerr<<"error opening the file primes!!"<<endl;
- while(!inFile.eof())
- {
- i++;
- inFile>>Primes_1;
- } //已经指向末尾
- i=i-1;
- cout<<i<<endl;
- inFile.seekg(0,ios::beg); //想让它指到开始的地方
- for(j=0;j<i;j++)
- {
- inFile>>Primes;
- cout<<setw(10)<<Primes;
- (j%5==0)?cout<<"\n":cout<<" ";
- }
- cout<<endl;
- inFile.close();
- return 0;
- }
复制代码 |
|