C++ map<string, vector< pair<string, string> > > family;输出的问题。
#include<iostream>#include<utility>#include<map>#include<vector>#include<string>using...
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <string>
using namespace std;
int main()
{
map<string, vector< pair<string, string> > > family;
string familyName("wangshifuifeng!");
vector< pair<string, string> > member;
pair<string, string> information;
information = make_pair(familyName,familyName);
member.push_back(information);
family.insert(make_pair(familyName, member));
family.find(familyName);
请问怎么把family的内容输出呀?
// family[familyName].begin().first;
return 0;
} 展开
#include <utility>
#include <map>
#include <vector>
#include <string>
using namespace std;
int main()
{
map<string, vector< pair<string, string> > > family;
string familyName("wangshifuifeng!");
vector< pair<string, string> > member;
pair<string, string> information;
information = make_pair(familyName,familyName);
member.push_back(information);
family.insert(make_pair(familyName, member));
family.find(familyName);
请问怎么把family的内容输出呀?
// family[familyName].begin().first;
return 0;
} 展开
展开全部
map<string, vector< pair<string, string> > > family;
for ( map<string, vector< pair<string, string> > >::iterator beg = family.begin();
beg != family.end();
++beg)
{
cout<<beg->first.c_str()<<endl;
for(vector< pair<string, string> >::iterator begvec = beg->second.begin();
begvec != beg->second.end();
++begvec)
{
cout<<"first:"<<begvec->first.c_str()<<endl;
cout<<"second:"<<begvec->second.c_str()<<endl;
}
}
遍历所有元素,找到你需要的然后输出就行了。
for ( map<string, vector< pair<string, string> > >::iterator beg = family.begin();
beg != family.end();
++beg)
{
cout<<beg->first.c_str()<<endl;
for(vector< pair<string, string> >::iterator begvec = beg->second.begin();
begvec != beg->second.end();
++begvec)
{
cout<<"first:"<<begvec->first.c_str()<<endl;
cout<<"second:"<<begvec->second.c_str()<<endl;
}
}
遍历所有元素,找到你需要的然后输出就行了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询