读书人

编译异常为什么

发布时间: 2012-08-08 14:32:45 作者: rapoo

编译错误,为什么
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <string>

using namespace std;

int main()
{
map<string, vector<string> > children;
string surname, childName, birthday;

do {
cout << "Enter surname(Ctrl+Z to end):" << endl;
cin >> surname;
if (!cin)
break;
vector< pair<string, string> > chd;
pair<map< string, vector< pair<string, string> > >::iterator, bool> ret =
children.insert(make_pair(surname, chd));
if (!ret.second) //该家族姓氏已在容器map中存在
{
cout << "repeated surname: " << surname << endl;
continue;
}
cout << "Enter children's name(Ctrl+Z to end):" << endl;

while (cin >> childName >> birthday)
ret.first->second.push_back(make_pair(childName, birthday));
cin.clear();

}while(cin);

cin.clear();

cout << "Enter a surname to search:" << endl;
cin >> surname;

map< string, vector< pair<string, string> > >::iterator iter = children.find(surname);

if ( iter == children.end() )
cout << "no this surname: " << surname << endl;
else{
cout << "children\t\tbirthday: " << endl;
vector< pair<string, string> >::iterator it = iter->second.begin();
while (it != iter->second.end())
cout << it->first << "\t\t" it->second << endl;
it++;
}
getchar();
getchar();
return 0;
}

[解决办法]
map<string, vector<string> > children;

map< string, vector< pair<string, string> > >::iterator iter = children.find(surname);

类型不一致。
[解决办法]
有好多明显的错误,要是能编译通过,那么,那个编译器简直就是神了。

读书人网 >C++

热点推荐