I have string and a map<string,int>
i need to iterate through the map and find string[i] and replace the int with the string.
eg: if map contains
hello 6
world 4
its 3
me 60
if the string is "its me hello world world hello"
output should be "3 60 6 4 4 6"
i also tried
i get the same error
main.cpp:294: error: invalid conversion from `char' to `const char*'
main.cpp:294: error: initializing argument 1 of `std::basic_str ing<_CharT, _Traits, _Alloc>::basic_ string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_trait s<char>, _Alloc = std::allocator< char>]'
can someone please help me fix this!
thanks
drjay
i need to iterate through the map and find string[i] and replace the int with the string.
eg: if map contains
hello 6
world 4
its 3
me 60
if the string is "its me hello world world hello"
output should be "3 60 6 4 4 6"
Code:
for(int i = 0 ; i < str.length() ; i++){ it = mymap.find(str[i]); //it is iterator, mymap is map<string,int> myOutfile << (*it).second; //myOutfile is out stream }
Code:
for(itStr its = str.begin() ; its < str.end(); its++ ){ itf = myMap.find(*its); myOutfile << (*itf).second; }
main.cpp:294: error: invalid conversion from `char' to `const char*'
main.cpp:294: error: initializing argument 1 of `std::basic_str ing<_CharT, _Traits, _Alloc>::basic_ string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_trait s<char>, _Alloc = std::allocator< char>]'
can someone please help me fix this!
thanks
drjay
Comment