qfedu-cpp-level/day9/homework/h5.cpp

21 lines
523 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 【场景】字符串拼接
// 编写一个函数 concatenateStrings接受两个字符串作为参数并返回它们的拼接结果。
#include <iostream>
#include <string>
using namespace std;
string concatenateStrings(const string &str1, const string &str2)
{
return str1 + str2;
}
int main()
{
string s1 = "hello";
string s2 = "world";
s1 = concatenateStrings(s1, " "); // 先拼接一个空格
s1 = concatenateStrings(s1, s2); // 再拼接 s2
cout << s1 << endl;
return 0;
}