64,649
社区成员
发帖
与我相关
我的任务
分享
#include <string>
#include <iterator>
#include <algorithm>
#include <fstream>
#include <iostream>
using namespace std;
bool IsSpecialChar(char ch)
{
//有几个字符与输入法有关;
const char *punc="~`!·#¥%…—*()—-+=、 |[]{}:;“”《,》。?/@$^&";
int len=strlen(punc);
for(int i=0; i<len; i++)
if( *(punc+i)== ch )
return true;
return false;
}
void RemovePunc(string &word)
{
string::iterator first, second;
first=find_if(word.begin(), word.end(), IsSpecialChar);
while (first != word.end())
{
second=word.erase(first, first+1);
first=find_if(second, word.end(), IsSpecialChar);
}
}
char FindSpecialChar(string word, char ch)
{
string::iterator dest;
dest=find(word.begin(), word.end(), ch);
if(dest != word.end())
return *dest;
return '\0';
}
int main()
{
string str;
cout<<"Input the string: ";
cin>>str;
cout<<FindSpecialChar(str, '+')<<endl;
RemovePunc(str);
cout<<str<<endl;
return 0;
}
不懂你‘取出字符’指的是什么意思啊,上面的FindSpecialChar函数根本没有任何意义,
参考一下吧,