std::map testMap;
testMap["answer"] = 42;
printf ("The answer is: %d", testMap["answer"]);
and get the output "The answer is: 42".
All *I* get, however, is compiler-errors.
The actual error is something like "class expected" (I don''t remember the exact message). And from mucking about a bit with it it seems that the compile expects 3 arguments within the <>''s.
Why?
Help appreciated.
-Neophyte
~Death awaits you all, with nasty, big, pointy teeth~
Problems with map<key, value>
I''ve got some problems using C++''s map-function.
Basically, I can''t get it to work at all...
As far as I''ve gathered from various texts, I should be able to do something like this:
The std::map template class needs 3 template parameters.
they are map< key, value, compare >
I''m guessing you wrote std::map<std::string, long >
The standard indicates that for the compare class, it defaults to less<key>
However, your compiler may not support default template parameters.
You must then write
std::map< std::string, long, less<std::string> >
Note that the space between those last two greater than signs is extremely important... you''ll get a boatload of compile errors without it.
they are map< key, value, compare >
I''m guessing you wrote std::map<std::string, long >
The standard indicates that for the compare class, it defaults to less<key>
However, your compiler may not support default template parameters.
You must then write
std::map< std::string, long, less<std::string> >
Note that the space between those last two greater than signs is extremely important... you''ll get a boatload of compile errors without it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement