P
Pallav singh
Hi All ,
i am getting an interesting problem
map<int , vector<string > & > tmp; // it donot work
map<int , vector<string > * > tmp; // it work
++++++++++++++++++++++++++++++++++++++++++++++++
kindly let me know the reason
#include <iostream.h>
#include <map>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector< string > v1 , v2;
map<int , vector<string > & > tmp;
map<int , vector<string > & >::iterator iter1,iter2;
tmp.insert(pair<int ,vector<string> & >(1,v1));
tmp.insert(pair<int ,vector<string> & >(2,v2));
v1.push_back("Pallav1");
v1.push_back("Sharmad1");
v1.push_back("Ajay1");
v2.push_back("Pallav2");
v2.push_back("Sharmad2");
v2.push_back("Ajay2");
for(int i = 0 ; i < v1.size() ; i++ )
cout<< v1.at(i) << endl;
for(int i = 0 ; i < v2.size() ; i++ )
cout<< v2.at(i) << endl;
iter1 = tmp.begin();
iter2 = tmp.end();
for(iter1 ; iter1 != iter2 ; iter1++ )
{ cout<<"++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"first value :: "<<(*iter1).first ;
for(int i = 0 ; i < ((*iter1).second)->size() ;i++)
cout<<((*iter1).second)->at(i) <<endl;
}
return 0;
}
Thanks
Pallav Singh
i am getting an interesting problem
map<int , vector<string > & > tmp; // it donot work
map<int , vector<string > * > tmp; // it work
++++++++++++++++++++++++++++++++++++++++++++++++
kindly let me know the reason
#include <iostream.h>
#include <map>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector< string > v1 , v2;
map<int , vector<string > & > tmp;
map<int , vector<string > & >::iterator iter1,iter2;
tmp.insert(pair<int ,vector<string> & >(1,v1));
tmp.insert(pair<int ,vector<string> & >(2,v2));
v1.push_back("Pallav1");
v1.push_back("Sharmad1");
v1.push_back("Ajay1");
v2.push_back("Pallav2");
v2.push_back("Sharmad2");
v2.push_back("Ajay2");
for(int i = 0 ; i < v1.size() ; i++ )
cout<< v1.at(i) << endl;
for(int i = 0 ; i < v2.size() ; i++ )
cout<< v2.at(i) << endl;
iter1 = tmp.begin();
iter2 = tmp.end();
for(iter1 ; iter1 != iter2 ; iter1++ )
{ cout<<"++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"first value :: "<<(*iter1).first ;
for(int i = 0 ; i < ((*iter1).second)->size() ;i++)
cout<<((*iter1).second)->at(i) <<endl;
}
return 0;
}
Thanks
Pallav Singh