us.name = "123";
cout << us.name << endl;
=====================================
程序运行时报一个异常
C2679:binary'<<':nooperatordefinedwhichtakesaright-handoperandoftype
错误原因:在#include<iostream.h>中string类没有重载"<<"操作符.
cout << us.name.c_str() << endl;
本文介绍了一个关于C++中使用cout输出string类型变量时遇到的问题及解决方法。当直接使用cout输出string时出现了编译错误,原因是string类未对<<操作符进行重载。文章提供了正确的输出方式,即将string转换为const char*类型。
us.name = "123";
cout << us.name << endl;
=====================================
程序运行时报一个异常
C2679:binary'<<':nooperatordefinedwhichtakesaright-handoperandoftype
错误原因:在#include<iostream.h>中string类没有重载"<<"操作符.
cout << us.name.c_str() << endl;
4万+

被折叠的 条评论
为什么被折叠?