I am trying to replace a substring with char*, the strng::replace refuses to take anything that is not a const string *
map<string,char *> renamed_files;
map<string,char *>::iterator rename_it;
Is t开发者_开发知识库here any way of using cPath to replace the substring in the map?
rename_it = renamed_files.begin();
char cPath[1024];
string strpath = cPath;
rename_it->first.replace(0,len, strpath);
No, the key in a map is const. Therefore the problem is that rename_it->first
is const but replace
is (of course) a non-const member function.
If you were to somehow modify it, that would change the correct position of the entry in the map, but the map has no way to detect that you're changing the string, so it can't move the entry. To avoid the whole problem, modification is forbidden.
You can remove the entry and add a new one with a different key but the same value. Be careful about the validity of your iterator as you do so.
精彩评论