#include <iostream>
#include <string>
using namespace std;
/*---------------------------------
18.41.结构体与string string类的调用 参数通过引用的方式调用
---------------------------------*/
string show1(string str)
{
cout<<str<<endl;
return str;
}
string& show2(string &str) //参数通过引用的方式调用
{
cout<<str<<endl;
return str;
}
int main()
{
string str1="hello world";
string str2=show1(str1);
cout<<str2<<endl;
cout<<"------------"<<endl;
str2=show2(str1); //参数通过引用的方式调用
cout<<str2<<endl;
return 0;
}
运行结果:
hello world
hello world
------------
hello world
hello world
Press any key to continue
C++ 字符串 15-- 18.41.结构体与string string类的调用 参数通过引用的方式调用
最新推荐文章于 2023-10-18 11:05:23 发布