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;
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;
相关文章推荐
- 解决 C++错误 error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no
- error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class Stude
- error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string'
- error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string'
- error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::wstring'
- error C2679: binary '<<' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion
- error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::wstring'
- error C2679: binary '<<' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion
- 错误 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::str
- C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::basic
- Error 1 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::
- error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::
- error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_s
- error C2677: binary '-' : no global operator defined which takes type 'class CString' (or there is n
- typeof + instanceof+toString+constructor是如何判断javascript数据类型的
- 【原】error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string'
- 如何在C++中方便的将float、int等类型数据转换成string类型,并利用ROS中的std_msg/String发布出去
- 如何在C++中方便的将float、int等类型数据转换成string类型,并利用ROS中的std_msg/String发布出去
- SQL Server 2008 中,将int数据类型如何转换为string输出?
- 如何判断js中的数据类型:typeof、instanceof、 constructor、 prototype方法比较