problem in printing the second element in map which is a vector

Can anyone please help me in this

the program is to define a map in which the key will be the surname and the element will be vector which contains the names of child.
the program that I have written and compiled in DEV C++ is given below.
I am facing problem is printing the second element of map-please help me.

#include<iostream>
#include<map>
#include<vector>
#include<string>
using namespace std;
int main(void)
{
int i,n;
string surname,mname;
map< string,vector<string> > v;
vector<string> name;
cout<<"Enter the no of names to be entered:";
cin>>n;
for(i=1;i<=n;i++)
{
cout<<"Enter the surname:";
cin>>surname;
cout<<"Enter the name:";
cin>>mname;
name.push_back(mname);
v.insert(make_pair(surname,name));
}
cout<<"Enter the surname to be searched:";
cin>>surname;
for(map< string,vector<string> >::iterator iter=v.begin();iter!=v.end();++iter)
{
if((*iter).first==surname)
{
cout<<iter->first;
cout<<iter->second; /*this is the one causing the problem*/
}
}
system("pause");
}
Hint: What data type is this?

 
iter->second
Last edited on
Topic archived. No new replies allowed.