编写函数fun( ),该函数功能是从字符串中删除指定的字符,同一字母的大小写按不同的字符处理。 例如:执行时输入的字符串是 turbo c and borland c++,从键盘上输入字符n,则输出为 turbo c ad borlad c++. 如果输入的字符在字符串中不存在,则原样输出。仅在函数fun的花括号中填入所编写的语句.
#include<iostream.h>
using namespace std;
void fun(char s[],int c)
{
}
int main()
{
static char str[]="turbo c and borland c++";
char ch;
cout<<"原始字符串:\n"<<str<<endl;
cout<<"输入一个字符:“;
cin>>ch;
fun(str,ch);
cout<<"str="<<str<<endl;
return 0;
}
我对这些都是一片茫然的,知道的麻烦教我一下~非常感谢!!
#include<iostream>
#include<string.h>
usingnamespacestd;
intmain(){
strings="-daas-j--kdj-al-";
string::iteratorit;
for(it=s.begin();it!=s.end();it++)
if(*it=='-'){
s.erase(it);
it--;
}
cout<<s<<endl;
return0;
}
扩展资料
C++从string中删除一个字符
#include<iostream>
#include<string>
#include<stdlib.h>
usingnamespacestd;
intmain()
{
stringstr="abddghj";
string::iteratorit;//指向string类的迭代器。你可以理解为指针
for(it=str.begin();*it!='';it++)
{
if(*it=='d')
{
str.erase(it);//删除it处的一个字符
break;
}
}
cout<<str<<endl;
system("pause");
return0;
}