I have the following problem related to iterating over an associative array of strings defined using std :: map.
-- snip -- class something { //... private: std::map<std::string, std::string> table; //... }
In the constructor, I populate the table with pairs of string keys associated with string data. Elsewhere, I have a toString method that returns a string object containing all the keys and its associated data contained in the table object (as key = data format).
std::string something::toString() { std::map<std::string, std::string>::iterator iter; std::string* strToReturn = new std::string(""); for (iter = table.begin(); iter != table.end(); iter++) { strToReturn->append(iter->first()); strToReturn->append('='); strToRetunr->append(iter->second());
When I try to compile, I get the following
error: "error: no match for call to" (std :: basic_string, std :: allocator>) () ".
Can someone explain to me what is missing, what am I doing wrong? I just found some discussion of a similar problem in the case of hash_map, where the user must define a hash function in order to be able to use hash_map with std :: string objects. Maybe something similar in my case?
Thank!
c ++ iterator stl map
crazybyte Jun 30 '09 at 23:51 2009-06-30 23:51
source share