10 Jul
2002
10 Jul
'02
10:48 a.m.
I have a container (map) with identifiers and value and would like to replace variables in a string. The function to perform the replacement I wrote needs a const_cast, which makes me a bit nervous. Is this necessary? Is there a better way to implement it?
You can't portably use const_cast with string::const_iterator, it works in this case because the iterator is just a pointer but that is not true on many platforms (VC7, STLport etc). Better is to use the form of replace that takes an int position and a length: s = s.replace( what[2].first - s.begin(), what.length(2), variables[ identifier ] ); John Maddock http://ourworld.compuserve.com/homepages/john_maddock/index.htm