syntax for a vector within a map

S

solartimba

I have put an vector array of values within a map. What I don't know
is the syntax for accessing the individual vector values.

map[key][vectorDex].someFunc does run the function but it also creates
a runtime error.

1. What is the proper syntax?

2. Is there anything wrong with choosing this type of structure? So
far, it works.
 
V

Victor Bazarov

solartimba said:
I have put an vector array of values within a map. What I don't know
is the syntax for accessing the individual vector values.

map[key][vectorDex].someFunc does run the function but it also creates
a runtime error.

Post the code, post the data, post the error (read FAQ 5.8).
1. What is the proper syntax?

For what?
2. Is there anything wrong with choosing this type of structure? So
far, it works.

If it works, nothing is wrong (performance can be substandard,
but that's not really "wrong").

Victor
 
M

Moonlit

Hi,

solartimba said:
I have put an vector array of values within a map. What I don't know
is the syntax for accessing the individual vector values.

You mean something like this

map<string, vector<string> > MapVector;

for( map<string, vector<string> >::const_iterator Walker =
MapVector.begin(); Walker != MapVector.end(); ++Walker )
{
cout << Walker->first << endl;
for( vector<string>::const_iterator WalkerVector = Walker->second.begin();
WalkerVector != Walker->second.end(); ++WalkerVector )
{
cout << *WalkerVector << endl;
}
}
map[key][vectorDex].someFunc does run the function but it also creates
a runtime error.

1. What is the proper syntax?

2. Is there anything wrong with choosing this type of structure? So
far, it works.
Nope, nothing wrong with it.

Regards, Ron AF Greve.
 
G

Grzegorz Sakrejda

I have put an vector array of values within a map. What I don't know
is the syntax for accessing the individual vector values.

map[key][vectorDex].someFunc does run the function but it also creates
a runtime error.

map[key] used first time will return a reference to the empty vector so
operator [] will have undefined behaviour.

1. What is the proper syntax?

map[key] returns vector& , vector can be empty.
2. Is there anything wrong with choosing this type of structure? So
far, it works.
Nothing wrong at all
 

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

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top