#include<iostream>
#include<fstream>
#include<string>
#include<vector>
using namespace std;
int main()
{
vector<string> svec;
cout<<"请输入要读取的文件名:"<<endl;
string fileName;
cin>>fileName;
ifstream inFile(fileName.c_str());
if(!inFile)
{
cout<<"文件读取错误!"<<endl;
return -1;
}
string s;
while(inFile)
{
inFile>>s;
// cout<<s.size()<<endl;
svec.push_back(s);
}
inFile.close();
cout<<"数据读取结果:"<<endl<<endl;
int i=0;
string ss;
for(vector<string>::const_iterator iter=svec.begin();iter!=svec.end()-1;iter++)
{
if (iter==svec.begin())
i=1;
if (i==10)
{
ss=*iter;
cout<<*iter<<endl;
break;
}
i++;
}
cout<<ss<<endl;
cout<<ss.size()<<endl;
return 0;
}
注意:文件名即txt文件的名称,