hi i need to look through a string of letters and change the letters simultaneously. so if i have aabbccttcc and do a change to c and c change to a. what happens is that first a change to c and that c changes back to a.
I don't really understand what you wanted, but it seems as if you want to change every char that is 'a' into 'c' and every char that is 'c' into 'a'?
Well replace or replace_if would iterate once, so doing 2 replaces will not suffice because you'd end up with no 'c' in the string. Here's what I think should answer your request.
1 2 3 4 5 6 7 8 9
std::string word("aabbccttcc");
for (std::string::iterator it = word.begin(); it != word.end(); ++it)
{
if (*it == 'a')
*it = 'c';
elseif (*it == 'c')
*it = 'a';
}
std::cout << word;