Mar 27, 2013 at 1:13am UTC
The goal is to remove vowels. Could someone help me with the string.at part... clearly my syntax is wrong. Thanks!
#include <string>
#include <iostream>
using namespace std;
void vowelremover(string&);
string word;
int main ()
{
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;
}
void vowelremover (string& enteredword)
{
int posvowel;
int i;
for (i == 0; i < enteredword.length(), i ++)
{
while (enteredword.at(i) = 'a'; || enteredword.at(i) = 'e'; || enteredword.at(i) = 'i'; || enteredword.at(i) = 'o'; ||
enteredword.at(i) = 'u'; || enteredword.at(i) = 'A'; || enteredword.at(i) = 'E'; || enteredword.at(i) = 'I'; || enteredword.at(i) = 'O'; ||
enteredword.at(i) = 'U';)
{
enteredword.erase(i, 1);
i == 0;
}
}
Mar 27, 2013 at 2:07am UTC
Hi PoolOfDeath, there are several mistakes. For the for loop, i < enteredword.length(),
, it should be i < enteredword.length();
.
Second, for the while condition, it should be enterword.at(i)=='a'
, with '==' and no';'.
Hope these help. :)
Mar 27, 2013 at 2:17am UTC
i had the enterword.at(i)='a' but it says 'a' has to be a modifiable lvalue so it doesnt work. any idea on that?
Last edited on Mar 27, 2013 at 2:25am UTC
Mar 27, 2013 at 2:58am UTC
so now i'm getting the error "Unhandled exception at 0x770b15de in VowelDeleter.exe: Microsoft C++ exception: std:)out_of_range at memory location 0x003ef9c4.."