【发布时间】:2014-01-28 08:30:49
【问题描述】:
当我输入aeiou AEIOU 时,这是我的代码,它只输出xxxxx 我哪里出错了???我想替换整个字符串中的每个元音,但我只对第一个单词这样做是我的代码错误吗??
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
class remove_vowels_class
{
private:
public:
void remove_vowels_accept(string the_string)
{
std::replace(the_string.begin(),the_string.end(),'a','x');
std::replace(the_string.begin(),the_string.end(),'A','x');
std::replace(the_string.begin(),the_string.end(),'e','x');
std::replace(the_string.begin(),the_string.end(),'E','x');
std::replace(the_string.begin(),the_string.end(),'i','x');
std::replace(the_string.begin(),the_string.end(),'I','x');
std::replace(the_string.begin(),the_string.end(),'o','x');
std::replace(the_string.begin(),the_string.end(),'O','x');
std::replace(the_string.begin(),the_string.end(),'u','x');
std::replace(the_string.begin(),the_string.end(),'U','x');
std::replace(the_string.begin(),the_string.end(),'~',' ');
cout<<"the replaced string is :"<<the_string<<endl;
}
};
int main()
{
remove_vowels_class maniobj;
string input_string;
cout<< "Enter a string to replace all vowels:"<<endl;
cin>>input_string;
std::replace(input_string.begin(),input_string.end(),' ','~');
maniobj.remove_vowels_accept(input_string);
【问题讨论】:
-
打印
input_string会看到什么? -
您真的需要将 Emacs 模式行放在问题中吗?
标签: c++