挺不解的错误
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<map>
using namespace std;
typedef vector<string>vstring;
void populate_map(ifstream &infile,map<string,vstring>&map_name)
{
string textline;
while(getline(infile,textline))
{
string fam_name;
vector<string>child;
string::size_type pos=0,pre_pos=0,text_size=textline.size();
//找出一空格符分割开来的所有单词
while((pos=textline.find_last_of(' ',pos))!=string::npos)
{
string::size_type end_pos=pos-pre_pos;
if(!pre_pos)
fam_name=textline.substr(pre_pos,end_pos);
else
child.push_back(textline.substr(pre_pos,end_pos));
pre_pos=++pos;
}
//处理之后一个孩子的姓名
if(pre_pos<text_size)
child.push_back(textline.substr(pre_pos,pos-pre_pos));
if(!map_name.count(fam_name))
map_name[fam_name]=child;
else
{
cerr<<"we have have a "<<fam_name<<"family in our family"<<endl;
}
}
}
void dispaly_map( const map<string,vstring>&family,ostream &os)
{
map<string,vstring>::const_iterator iter=family.begin();
while(iter!=family.end())
{
os<<iter->first<<" ";
if(iter->second.empty())
os<<"has no children:"<<endl;
else
{
vector<string>::const_iterator it->second.begin();
while(it!=iter->second.end())
{
os<<*it<<" ";
it++;
}
os<<endl;
}
iter++;
}
}
void quer_map(const string &family,const map<string,vstring>&families)
{
map<string,vstring>::const_iterator it=families.find(family);
if(it!=families.end())
{
cout<<"sorry,the"<<family<<" is not exist"<<endl;
return;
}
cout<<"the"<< family;
if(!it->second.size())
cout<<"has no childen"<<endl;
else
{
//打印出vector中的所有小孩
vector<string>::const_iterator iter=it->second.begin();
while(iter!=it->second.end())
{
cout<<*iter<<" ";
iter++;
}
cout<<endl;
}
}
int main()
{
map<string,vstring>families;
string filename;
string str;
ifstream infile;
cout<<"输出文件名"<<endl;
cin>>filename;
infile.(filename);
if(!infile)
{
cerr<<"can't open for reading"<<endl;
return -1;
}
populate_map(infile,families);
string familyname;
while(cin>>familyname)
query_map(familyname,families);
display_map(families,cout);
return 0;
}
\编程练习\mao容器家族(文件式.cpp(48) : error C2143: syntax error : missing ';' before '->'
e:\编程练习\mao容器家族(文件式.cpp(48) : error C2143: syntax error : missing ';' before '->'
e:\编程练习\mao容器家族(文件式.cpp(95) : error C2059: syntax error : '('
e:\编程练习\mao容器家族(文件式.cpp(96) : error C2039: 'infile' : is not a member of 'basic_ifstream<char,struct std::char_traits<char> >'
e:\编程练习\mao容器家族(文件式.cpp(98) : error C2039: 'cerr' : is not a member of 'basic_ifstream<char,struct std::char_traits<char> >'