//交替合并字符串
#include <iostream>
#include<string>
using namespace std;
class Sloution
{
public:
string swap(string word1, string word2)
{
string res = " ";
int i = 0;
while (i < word1.length() || i < word2.length())
{
res =res+word1[i];
res =res+word2[i];
i++;
}
return res;
}
};
int main()
{
Sloution s;
cout<<s.swap("abcd","def");
return 0;
}
注:length函数是编译器的函数库提供的,不用自己写这个函数,就可以实现调用