Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ newbie trying to cope with STL Maps 2

Status
Not open for further replies.

billbose

Programmer
Jan 15, 2001
66
US
I am trying to use STL map like 'hash of arrays' in Perl.

For eg in Perl hash of array,

%HoA = (
flintstones => [ "fred", "barney" ],
jetsons => [ "george", "jane", "elroy" ],
simpsons => [ "homer", "marge", "bart" ],
);


print $HoA{flintstones}[0] ; # will give fred as output

Is it possible to do a similar thing in STL Map.
TiA
 
You can do something like this:
Code:
map<string, vector<string> > mapOfArrays;
vector<string> array1;
array1.push_back( "One" );
array1.push_back( "Two" );
array1.push_back( "Three" );
map[ "numbers" ] = mapOfArrays;
...
 
There's some typos in your code, cpjust, but an even better solution would be:
Code:
map<string, vector<string> > mapOfArrays;
mapOfArrays[ "numbers" ].push_back( "One" );
mapOfArrays[ "numbers" ].push_back( "Two" );
mapOfArrays[ "numbers" ].push_back( "Three" );
 
Your welcome, but you should thank cpjust. I just tweaked his solution. :)
 
No problem.
Maybe it's just dyslexia from lack of sleep, but I can't see any typos...?
 
Code:
map[ "numbers" ] = mapOfArrays;
was probably supposed to be
Code:
mapOfArrays[ "numbers" ] = array1;
 
Ah, now I see... :) This z/OS training is rotting my brain cells.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top