您的位置:首页 > 编程语言 > C语言/C++

C++,如何输出string类型的数据(报错:no operator defined which takes a right-hand operand of type 'class std::bas)

2017-05-22 22:41 766 查看
1、错误提示:

 binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable

conversion)

2、错误原因:

#include<iostream.h>

#include<string>

using namespace std;

在#include<iostream.h>中string类没有重载“<<”操作符

3、错误代码:

string str=" ";

cout<<str<<endl;

4、解决办法(string.c_str是Borland封装的String类中的一个函数,它返回当前字符串的首字符地址;

                       c_str()函数返回一个指向正规C字符串的指针, 内容与本string串相同.)

string str=" ";

cout<<str.c_str()<<endl;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐