using map item without assigning onw first?

G

Gernot Frisch

Can I do this:

std::map<long, std::vector<long>> snapmap;
long i=4, j=0;
snapmap[j].push_back(i);


--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
 
J

John Harrison

Gernot Frisch said:
Can I do this:

std::map<long, std::vector<long>> snapmap;
long i=4, j=0;
snapmap[j].push_back(i);

Yes, using snapmap[j] will create a map entry using the default constructor
for std::vector<long>. You then push back i onto that empty vector.

john
 

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

Similar Threads

int(a) vs (int)a 19
reference to parent inherritance? 9
queue where I can delete in the middle? 3
unreachable code? 4
std::list - access at index? 3
a[3} slower than a.x; a.z; a.z 27
boost 2
a thread safe stack? 7

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top