- 论坛徽章:
- 0
|
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <vector>
using namespace std;
int main()
{
vector <string> svec1, svec2;
ifstream infile("test.txt", ios_base::in);
if (infile.fail())
{
cerr << "open the file fail" << endl;
exit(1);
}
string str;
while (!infile.eof())
{
getline(infile, str);
svec1.push_back(str);
}
infile.seekg (0, ios::beg);
while (!infile.eof())
{
getline(infile, str);
svec2.push_back(str);
}
cout << svec2.size() << endl; //这里输出为0
return 0;
} |
test.txt的内容为:
abcdefg
xyz
lmn
opq
seekg的作用应该是Sets the position of the get pointer.
为啥那个地方打印出来的还是0呢??? |
|