首先,需明白元音字母都有哪些。通常来说,有以下5个元音,即a、e、i、o、u。删除字符串中的元音字母即要求遍历字符串找到元音字母并删除。
例如,有个字符串为“Welcome to the world!”,删除元音字母后字符串变为“Wlcm t th wrld!”。
最简单方法就是依次遍历每个字符,如果是元音字母,则删除。
#include <iostream>
using namespace std;
void DelVowels(char* s)
{
int i = 0;
int j = 0;
while (s[j] != '\0')
{
while (s[j] == 'a' || s[j] == 'e' || s[j] == 'i' || s[j] == 'o' || s[j] == 'u')
{
j++;
}
s[i++] = s[j++];
}
s[i] = '\0';
cout << s;
cout << endl;
}
int main()
{
char str[100];
gets(str);
DelVowels(str);
return 0;
}