I've tried:
versionString = versionString.replace(versionString.begin(), versionString.end(), '(' , '-' );
The result is: "--------------". Basically replacing all the characters. What is that?
versionString is a basic string.
I've tried:
versionString = versionString.replace(versionString.begin(), versionString.end(), '(' , '-' );
The result is: "--------------". Basically replacing all the characters. What is that?
versionString is a basic string.
If you look at e.g. this std::string::replace
reference you will see that there's no overload that takes the arguments you pass. Something the compiler really should warn you about.
The closes one is number 6:
basic_string& replace( const_iterator first, const_iterator last,
size_type count2, CharT ch );
which replaces the range with count2
copies of ch
.
That is, you replace your string with '('
number of dashes. With ASCII that '('
will be converted to the integer 40
(it's this conversion the compiler should have warned you about).
One solution is to repeatedly find
the character you want to replace, and replace only that single character.
A much simpler solution is to use the standard algorithm function std::replace
:
std::replace(begin(versionString), end(versionString), '(', '-');