C++实现指定的字符串替代(华为)

来源:互联网 发布:mac开机显示客人用户 编辑:程序博客网 时间:2024/06/16 02:32
#include<iostream>#include<cstring>#include<string>#include<cstdlib>using namespace std;/*void replace(char *str_src,char *str_find,char *str_replace){if(NULL==str_src||str_find==NULL||str_replace==NULL)return ;char *head=str_src;int length1=strlen(str_find);int length2=strlen(str_replace);while(*str_src!='\0'){if(*str_src==*str_find){if(strncmp(str_src,str_find,length1)==0){for(int i=0;i<length2;++i){*str_src=*(str_replace+i);str_src++;}}else{str_src++;}}else{str_src++;}}str_src=head;}int main(){char a[]="";char b[]="ggg";char c[]="zzz";replace(a,b,c);cout<<a<<endl;system("pause");return 0;}*/

0 0