I have no idea where to start, this is what the assignment says:
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the sting. For example, if str = "There" then after removing all the vowels, str = "The". After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel.
Can you call another function when using substr? I'm not sure how to do this?
This is all I have so far.. I know this has to be simple, but I just can't wrap my head around how to go about doing this.
Thanks in advance,
Brooke! :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <string>
usingnamespace std;
int isVowel(string);
int removVowel(string);
int main()
{
string str;
cout << "Enter a string:" << endl;
cin>> str;
}
1. Take any string as a input from user.
2. call function RemoveVowels()
prototype of function should be:-
string RemoveVowels(string inputString);
This function returns you final substring after removing all vowels in given input string.
3. In this function you have to call another function who tell you whether character in string is vowel or not?
prototype should be:-
#include <iostream>
#include <string>
#include <cstddef>
int main()
{
std::cout << "Enter some text: ";
std::string str;
std::cin >> str; // Only one word, but whatever
std::string result;
// This just goes up to the first vowel
std::size_t firstVowelPos = str.find_first_of("aeiouAEIOU");
result += str.substr(0, firstVowelPos);
std::cout << result;
}
Enter some text: throw
thr
To get everything else, you'll have to make lines 13-14 into a loop somehow. (Hint: keep track of the position of the last vowel that you found, so you know which position to start from for find_first_of and substr.)
Okay this is what I have so far.. Thanks for everyone's help!!
I still have two problems..
1. It is only reading the first word of my string, I've tried using con.getline and it isn't letting me.
2. I don't know how to change what I already have to use substr (since that was a requirement of the assignment).
To read more than one word, use std::getline(std::cin, myString);.
And...did you forget to copy/paste your code?
Anyways, I gave you an example using substr to get the first part of the string (up to the first vowel).
You just need to find a way to loop through the rest of the string and repeat.