★ 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....btw
Thanks! Anyone's imput is highly extolled!
// Strings are your friends.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
usingnamespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string firstname, lastname;
size_t found;
cout << "Enter your first name.\n";
cin >> firstname;
cout << "Enter your last name.\n";
cin >> lastname;
//String object that store another two string objects
string Name = firstname + " " + lastname;
cout << "The name is : " << Name << endl;
size_t Name.find(char'a', 'e', 'i' , 'o', 'u', size_t pos = 0);
system("pause");
return 0;
}
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
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.
// Strings are your friends.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
int _tmain(int argc, _TCHAR* argv[])
{
std::string firstname, lastname;
constchar *vowels = "aeiou";
std::cout << "Enter your first name: ";
std::cin >> firstname;
std::cout << "Enter your last name: ";
std::cin >> lastname;
//String object that store another two string objects
std::string Name = firstname + " " + lastname;
std::cout << "\nThe name is: " << Name << std::endl;
std::string::size_type n = 0;
while ( ( n = Name.find_first_of( vowels, n ) ) != std::string::npos )
{
Name.replace( n, 1, 1, 'z' );
n++;
}
std::cout << "\nNow the name is: " << Name << std::endl;
return 0;
}