为什么我试图打印“reference_wrapper for string”的行对不支持的 operator<< “reference_wrapper for string”给出错误,但没有给出“reference_wrapper for int”?
int main(){
int s= 43;
string str = "hello";
reference_wrapper<int> x{s};
reference_wrapper<string> y{str};
x.get() = 47;
y.get() = "there";
cout<<"printing original int "<<s<<"\n";
cout<<"printing original string "<<str<<"\n";
cout<<"printing reference_wrapper for int "<<x<<"\n";
cout<<"printing reference_wrapper for string "<<y<<"\n"; // gives error
int& refint = x;
string& refstr = y;
cout<<"printing reference for int "<<refint<<"\n";
cout<<"printing reference for string "<<refstr<<"\n";
}