looking for a easier way to use strings

Is there a simpler way of changing the vowels by another character of a name using string functions without be this way?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <conio.h>
#include <string>

using namespace std;

int main() {
    string firstname, lastname;
    size_t found;
    
    cout << "Enter your first name: ";
    cin >> firstname;
    cout <<  "Enter your last name: ";
    cin >>  lastname;
    cout << "\n" << firstname << " " << lastname << endl;
    
    found = firstname.find_first_of("aeiou");
          while (found != string::npos) {
                firstname[found] = 'z';
                found = firstname.find_first_of("aeiou", found + 1);
          }
    found = lastname.find_first_of("aeiou");
          while (found != string::npos) {
                lastname[found] = 'z';
                found = lastname.find_first_of("aeiou", found + 1);
          }
          
    cout << firstname << " " << lastname << endl;
    
    getch();
    return 0;
}


And how do you invert the letters of a name??

ex: Francisco Maerle
ocsicnarF elreaM
2) std::reverse or operate it backwards (the user do not need to know)

1) Iterate trough the string and if you found a match, change it (that is what you are doing)
Recursive divide the string till you get just one character, change it if needed and "reassemble" (parallel processing)
s/[aeiou]/z/g Regex
Topic archived. No new replies allowed.