谁可以帮我看下是哪错了? 是返回值错了吗?
#include <iostream>#include <fstream>
#include <string>
#include <vector>
using namespace std;
int filetovector(string filename,vector<string>& svec)
{
ifstream infile(filename.c_str());
if (!infile)
return 1;
string s;
while (infile>>s)
{
svec.push_back(s);
}
infile.close();
if (infile.eof())
{
return 4;
}
if (infile.bad())
{
return 2;
}
if (infile.fail())
{
return 3;
}
}
int main()
{
vector<string> svec;
string filename,s;
cout<<"Enter filename: "<<endl;
cin>>filename;
switch (filetovector(filename,svec))
{
case 1:
cout<<"error: can not open file: "<<filename<<endl;
return -1;
case 2:
cout<<"error: system laliure "<<endl;
return -1;
case 3:
cout<<"error: read laliure "<<endl;
return -1;
}
cout<<"vector:"<<endl;
for (vector<string>::iterator iter=svec.begin();iter!=svec.end;--iter)
{
cout<<*iter<<endl;
}
return 0;
}