Need someone to help me with the next step. (basic)

The program should find and delete all vowels in a word that is user entered. This is what I have so far and I know it should be essentially this format I just don't know how to set enteredword and word equal to each other. thanks.



#include <string>
#include <iostream>
using namespace std;


void vowelremover(string&);

int main ()
{

string word;

cout << "Enter a word of which you want the vowels removed: ";
cin >> word;

vowelremover(word);

cout << "The word without vowels is: " << word << endl;

return 0;

}
string enteredword;

void vowelremover (string& enteredword)
{
int posvowel;

posvowel = enteredword.find("a,e,i,o,u,A,E,I,O,U");

while (posvowel >= 0 && posvowel < enteredword.length())
{
enteredword.erase(posvowel, 1);

posvowel = enteredword.find("a,e,i,o,u,A,E,I,O,U");
}

}
Last edited on
Where?
well it doesn't work... i was wondering how to get enteredword to equal word and also the enteredword.find("a,e,i,o,u,A,E,I,O,U"); doesnt work cause I think you can only evaluate one character at a time.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <string>

const std::string WOVELS = "aeiouAEIOU" ; // only English 

std::string wovel_remover_1( std::string word )
{
    for( auto pos = word.find_first_of(WOVELS) ;
          pos != std::string::npos ;
          pos = word.find_first_of(WOVELS) ) word.erase( pos, 1 ) ;
    return word ;
}

#include <algorithm>

std::string wovel_remover_2( std::string word )
{
    const auto is_wowel = [] ( char c ) { return WOVELS.find(c) != std::string::npos ; } ;
    word.erase( std::remove_if( word.begin(), word.end(), is_wowel ), word.end() ) ;
    return word ;
}
Topic archived. No new replies allowed.