how to start use nested STL container

G

guorke

Hi,all
I want to learn something about nested stl containers, but i
can't find any tips on it(such as
faq, c++ books etc), so anybody can give a good link (or good book)
which talk about it?

It's peffect if it have some examples.

Thanks all.
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

Hi,all
I want to learn something about nested stl containers, but i
can't find any tips on it(such as
faq, c++ books etc), so anybody can give a good link (or good book)
which talk about it?

It's peffect if it have some examples.

There's really not much to it, you just parametrise the outer container
with the inner and start using it.

std::map<int, std::vector<double> > m;

m[1].push_back(1.5);
m[1].push_back(1.4);
m[2].push_back(3.56);
m[3].push_back(13.65);
m[1].push_back(2.5);
 
G

guorke

Ok,
but no anybody knows how a link about this?
like, map<int,map<int,int> > mapf; I still not know how to insert into
mapf.

so i still need some tips about nested containers.
Thanks & Best Wishes.
 
I

Ian Collins

guorke wrote:

Please retain context.
Ok,
but no anybody knows how a link about this?
like, map<int,map<int,int> > mapf; I still not know how to insert into
mapf.
Just follow the normal rules for inserting. Maybe a typedef would make
it clearer?

typedef std::map<int,int> IntMap;

std::map<int, IntMap> mapf;
 
G

guorke

Many Thanks.
[] operator can deal with nested containers like this,
std::map<std::string , std::map<std::string , std::string> > m_values;
std::map<std::string , std::map<std::string , int> > m_lines;
const std::string section;
const std::string key;
const std::string value;
int line =0;

m_values[section][key] = value;
line =m_lines[section][key];
How can i understand it?
 
G

guorke

Many Thanks.
[] operator can deal with nested containers like this,
std::map<std::string , std::map<std::string , std::string> > m_values;
std::map<std::string , std::map<std::string , int> > m_lines;
const std::string section;
const std::string key;
const std::string value;
int line =0;

m_values[section][key] = value;
line =m_lines[section][key];
How can i understand it?
 
B

BobR

guorke said:
Ok,
but no anybody knows how a link about this?
like, map<int,map<int,int> > mapf; I still not know how to insert into
mapf.

so i still need some tips about nested containers.
Thanks & Best Wishes.

{
std::map<int, std::map<int, int> > mapf;
std::map<int, int> Imapf;
Imapf[1] = 1;
mapf[1] = Imapf;
mapf[1][2] = 2;
std::cout<<"mapf[1][2] ="<<mapf[1][2]<<std::endl;
mapf[1].insert( std::pair<int, int>(3, 3) );
cout<<"mapf[1][3] ="<<mapf[1][3]<<std::endl;
}
/* -output-
mapf[1][2] =2
mapf[1][3] =3
*/

Learn each container/sequence separately. Then worry about combining them.

Dinkumware:
http://www.dinkumware.com/manuals/.
 
G

guorke

Many Thanks.
[] operator can deal with nested containers like this,
std::map<std::string , std::map<std::string , std::string> > m_values;
std::map<std::string , std::map<std::string , int> > m_lines;
const std::string section;
const std::string key;
const std::string value;
int line =0;

m_values[section][key] = value;
line =m_lines[section][key];
How can i understand it?
 
I

Ian Collins

guorke wrote:

Where's the context?
Many Thanks.

You don't have to post 3 times.
[] operator can deal with nested containers like this,
std::map<std::string , std::map<std::string , std::string> > m_values;
std::map<std::string , std::map<std::string , int> > m_lines;
const std::string section;
const std::string key;
const std::string value;
int line =0;

m_values[section][key] = value;
line =m_lines[section][key];
How can i understand it?
By practice? Break the expression down and follow each part, only you
can do the understanding.
 
G

guorke

Many Thanks.
[] operator can deal with nested containers like this,
std::map<std::string , std::map<std::string , std::string> > m_values;
std::map<std::string , std::map<std::string , int> > m_lines;
const std::string section;
const std::string key;
const std::string value;
int line =0;

m_values[section][key] = value;
line =m_lines[section][key];
How can i understand it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top