题目描述
不用strcat 函数,自己编写一个字符串链接函数MyStrcat(char dstStr[],charsrcStr[])
输入描述
两个字符串,字符串由小写字母组成。
输出描述
链接后的字符串
输入
hello world
good morning
输出
helloworld
goodmorning
代码
方法一:
#include<iostream>
using namespace std;
int main(){
//不用strcat 函数,自己编写一个字符串链接函数
//MyStrcat(char dstStr[],charsrcStr[])
string str;
int pos;
while(getline(cin,str)){
pos=str.find(' ');
while(pos>=0&&pos<str.size()){
str=str.substr(0,pos)+str.substr(pos+1);
pos=str.find(' ');
}
cout<<str<<endl;
}
return 0;
}
7907



被折叠的 条评论
为什么被折叠?



