读书人

急open_file()没法使用

发布时间: 2013-03-16 11:51:46 作者: rapoo

急急急!open_file()无法使用。
看C++primer时打程序,发现open_file()居然无法使用。

#include<iostream>
#include<map>
#include<string>
#include<fstream>
#include<sstream>
#include"1234.h"
using namespace std;
int main(int argc,char **agrv){
map<string,string> trans_map;
string key,value;
if(argc!=3)
throw runtime_error("wrong number of arguments");
ifstream map_file;
if(!open_file(map_file,agrv[1]))
throw runtime_error("no transformation file");
while(map_file>>key>>value)
trans_map.insert(make_pair(key,value));
ifstream input;
if(!open_file(input,agrv[2]))
throw runtime_error("no putformation file");
string line;
while(getline(input,line)){
istringstream stream(line);
string word;
bool firstword(true);
while(stream>>word){
map<string,string>::const_iterator map_it=trans_map.find(word);
if(map_it!=trans_map.end())
word=map_it->second;
if(firstword)
firstword=false;
else
cout<<" "<<word;
}
cout<<endl;
return 0;
}

代码在C++primer第四版 P318
[解决办法]
引用:
也就是说open_file()不是库函数对吧。

回复 的时候用引用,这样回答的人才能看到。。。。。。。。。。。

读书人网 >C++

热点推荐