/* 7. Create two functions, one that takes a string* and one
that takes a string&. Each of these functions should
modify the outside string object in its own unique way.
In main( ), create and initialize a string object, print it,
then pass it to each of the two functions, printing the
results.
定义两个函数,一个获取string*,一个获取string&。每一个函数
以其特有的方式修改外部string对象。
在main()函数里,创建并定义一个string对象,打印出来,然后将
它传递给这两个函数,将结果打印出来。
*/
#include<iostream>
#include<string>
using namespace std;
void func1(string* a){
*a=*a+*a;
}
void func2(string& a){
a=a+a;
}
void main(){
string t="abc";
func1(&t);
cout<<t<<endl;
func2(t);
cout<<t<<endl;
}
that takes a string&. Each of these functions should
modify the outside string object in its own unique way.
In main( ), create and initialize a string object, print it,
then pass it to each of the two functions, printing the
results.
定义两个函数,一个获取string*,一个获取string&。每一个函数
以其特有的方式修改外部string对象。
在main()函数里,创建并定义一个string对象,打印出来,然后将
它传递给这两个函数,将结果打印出来。
*/
#include<iostream>
#include<string>
using namespace std;
void func1(string* a){
*a=*a+*a;
}
void func2(string& a){
a=a+a;
}
void main(){
string t="abc";
func1(&t);
cout<<t<<endl;
func2(t);
cout<<t<<endl;
}