D
Duane Hebert
2 questions:
Given a map defined as
std::map<int,string> stringmap;
//How do you access the data_type (string) via an iterator?
std::string spoo("doh");
stringmap.insert(std::make_pair(1,spoo));
// I tried this:
for(std::map<int,string> ::iterator it = stringmap.begin(); it !=
stringmap.end(); ++it)
std::cout << *it;
But this doesn't compile with error that the operator+ has not been defined
....
I think the problem is that the iterator returns a pair. Is it possible to
do this?
I know I can do:
if(stringmap.find(1) != stringmap.end()) std::cout << stringmap[1];
2nd question:
This doesn't work with BCB6 (causes a compile error about casting a pair to
an int???)
//stringmap is defined as a private class member
const std::string classname::getstring(size_t index) const { return
stringmap[index];}
but this compiles fine and seems to work with no problems:
const std::string classname::getstring(size_t index) { return
stringmap[index];}
Is this correct? Why can I not define this function as const? It's not
changing any
member data.
Thanks.
Given a map defined as
std::map<int,string> stringmap;
//How do you access the data_type (string) via an iterator?
std::string spoo("doh");
stringmap.insert(std::make_pair(1,spoo));
// I tried this:
for(std::map<int,string> ::iterator it = stringmap.begin(); it !=
stringmap.end(); ++it)
std::cout << *it;
But this doesn't compile with error that the operator+ has not been defined
....
I think the problem is that the iterator returns a pair. Is it possible to
do this?
I know I can do:
if(stringmap.find(1) != stringmap.end()) std::cout << stringmap[1];
2nd question:
This doesn't work with BCB6 (causes a compile error about casting a pair to
an int???)
//stringmap is defined as a private class member
const std::string classname::getstring(size_t index) const { return
stringmap[index];}
but this compiles fine and seems to work with no problems:
const std::string classname::getstring(size_t index) { return
stringmap[index];}
Is this correct? Why can I not define this function as const? It's not
changing any
member data.
Thanks.