#include<iostream>
#include<string>
using namespace std;
int test(){
string s;
cout<<"请输入一个字符串,可以包含空格:"<<endl;
getline(cin,s); //读取整行,遇回车符结束
for(auto &c:s){
c ='X';
}
cout<<s<<endl;
return 0;
}
运行结果:
此处c变量有两个特点,1,使用了auto,2,使用了引用,即c是s字符串中的任意字符的别名