首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

编译异常,为什么

2012-08-08 
编译错误,为什么#include iostream#include utility#include map#include vector#include string

编译错误,为什么
#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);

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

热点排行