| Kovs95 (52) | |||
|
★ Modify the program so that it then replaces every a, e, i , o, u w/ the letter z. i.e. John Smith -> Jzhn Smzth I am going to use the find() and replace() string functions to locate and replace the characters. This is my first time doing this so I am trying to teach myself. I wrote a part of the find function but it underlines the period Name.findin red for some reason. Any ideas of why this happens? The error says expected a semicolon....btwThanks! Anyone's imput is highly extolled!
| |||
|
Last edited on
|
|||
| Aceix (476) | |
Try omitting the size_t at the beginning of the line.Name.find(char 'a', 'e', 'i' , 'o', 'u', size_t pos = 0);HTH, Aceix. | |
|
|
|
| Kovs95 (52) | |
When I do that, the char 'a' becomes underlined and it says "type name is not allowed" and "expected a ')'.... I am obviously not done with the function but I don't think it should be a problem
| |
|
Last edited on
|
|
| Kovs95 (52) | |
One question that would help my understanding: In the example, what is size_t found;? Can someone explain if (found!=string::npos) from the example? It says that the "member value npos is returned" if whatever your finding is not found. How do they return those random values for npos? http://www.cplusplus.com/reference/string/string/find/ | |
|
|
|
| Aceix (476) | |
|
No, npos is a constant value, -1. Therefore, if (found!=string::npos) means if found is not equal to -1.HTH, Aceix. | |
|
Last edited on
|
|
| cire (2347) | |
|
First, find_first_of is the function you want to use. http://www.cplusplus.com/reference/string/string/find_first_of/ http://www.cplusplus.com/reference/string/string/find/ char 'a', 'e', 'i' is nonsensical.A 'sequence' of chars can be indicated with a string literal: Name.find( "aeiou", pos ) size_t pos = 0 is also nonsensical in the context of a function call. Default parameters are supplied in function declarations or definitions, not in function calls. | |
|
|
|
| Kovs95 (52) | |
|
But I never put in parameters into my function declaration/definition. Look at my code! Does that mean it starts at pos=0 by default? By the way, the link http://www.cplusplus.com/reference/string/string/find_first_of/ says to use "find()" if your looking for multiple characters... | |
|
Last edited on
|
|
| vlad from moscow (3662) | |||
| |||
|
|
|||