📄 +
字号:
【例3.8】 演示string对象引用的例子。
#include <iostream>
#include <string>
using namespace std;
void main(){
string s1=″We are here!″;
string&str=s1;//str引用s1
string* sp1=&s1;//string指针sp1指向对象s1
string*& sp2=sp1;//指针sp2引用指针sp1
cout<<″str=″<<str<<″,*sp1=″<<*sp1<<″, <<*sp2=″<<*sp2<<endl;
*sp2=″Go home!″;//通过引用指针使它们同步变化
cout<<″str=″<<str<<″,*sp1=″<<*sp1<<″,s1=″<<s1<<endl;
}
输出结果如下:
str=We are here!,*sp1=We are here!,*sp2=We are here!
str=Go home!,*sp1=Go home!,s1=Go home!
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -