如何读取计算机中的文件
int reservefile(string &filename,vector<string>& cont){
ifstream infile;
infile.close();
infile.clear();
infile.open(filename.c_str());
if(!infile)
return 1;
string line;
while(getline(infile,line)){
cont.push_back(line);
}
infile.close();
if(infile.eof())
return 2;
if(infile.bad())
return 3;
if(infile.fail())
return 4;
}
int main()
{
vector<string> cont;
string filename;
cout<<"enter your file name : "<<endl;
cin>>filename;
//检验错误
switch(reservefile(filename,cont)){
case 1:
cout<<"error: can't open : "<<filename<<endl;
return -1;
case 3:
cout<<"error: system failure "<<endl;
return -1;
case 4:
cout<<"error: read failure "<<endl;
return -1;
}
istringstream instr;
string str;
//输出每一个单词
for(vector<string>::const_iterator ip=cont.begin();ip!=cont.end();++ip){
instr.str(*ip);
while(instr>>str){
cout<<str;
}
instr.clear();
}
return 0;
}
现在希望读取计算机中的文件,如何确定文件的路径?请指教
谢谢