maintain certain string

Hai. i just want to know if there is a way to maintain certain character in a reversed string? For example in string "good*morning*everyone". If reversed and the character '*' is maintained at their position it will be "enoy*revegni*nromdoog". I have done the reversing part but i am not sure how to maintain that '*'s at their position. Any suggestions, examples, and solutions will be gladly appreciated. Thank you.
1
2
3
4
5
6
7
8
9
10
11
12
13
  #include <iostream>

using namespace std;

int main()
{
    string phrase, reversePhrase;
    phrase = "go*od*morn*ing*everyone";
    reversePhrase = string(phrase.rbegin(), phrase.rend());
    cout << "the phrase: "<< phrase << endl;
    cout << "the reverse phrase: " << reversePhrase << endl;
    return 0;
}
You have to skip those positions. Use an explicit loop.
Another way is to remove the *s and record their positions, reverse the string, and then insert the *s at the correct positions again.
Topic archived. No new replies allowed.