注册 登录
编程论坛 C++教室

大侠进来帮帮忙,错误提示看不懂................

a632034079 发布于 2009-12-21 16:11, 635 次点击
--------------------Configuration: C加加构造函数析构函数 - Win32 Debug--------------------
Compiling...
main.cpp
E:\Windos32\C加加构造函数析构函数\main.cpp(139) : error C2679: 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 accep
table conversion)
执行 cl.exe 时出错.

C加加构造函数析构函数.exe - 1 error(s), 0 warning(s)
那位大哥帮我解释下上面的错误提示是什么意思啊...................
7 回复
#2
here123452009-12-21 16:18
可能是那个"<<"你用错了,最好把代码贴出来看下
#3
flyingcloude2009-12-22 00:06
需要重载<<操作符
#4
debroa7232009-12-22 00:48
可能如下代码会报这个错:
string str="aaaa";
cout<<str;
如果是这样,我想你使用了如下语句:
#include <iostream.h>
要正确使用就改为
#include<iostream>
using namespace std;
这两个看起一样,其实是不同的,可以到网上搜一下。
#5
a6320340792009-12-22 15:35
以下是引用debroa723在2009-12-22 00:48:49的发言:

可能如下代码会报这个错:
string str="aaaa";
cout<<str;
如果是这样,我想你使用了如下语句:
#include <iostream.h>
要正确使用就改为
#include<iostream>
using namespace std;
这两个看起一样,其实是不同的, ...
#include<iostream>
using namespace std;
我就这写的啊!为什么还错啊???


#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
class Student
{
public:
    Student(string no,string name,int age)
    {
        stuno = no;
        stuname = name;
        stuage = age;
    }
    void display();
    static string teachername;
private:
    string stuno;
    string stuname;
    int stuage;
};
string Student::teachername = "李老师";
void Student::display()
{
    cout << "班主任:" << teachername << endl;
    cout << "名字:" << stuname << "学号:" << stuno << "年龄:" << stuage << endl;
}
int main()
{
    Student stud1("1000","NC",20);
    stud1.display();
    Student stud2("1001","SB",12);
    stud2.display();
    cin.get();
    return 0;
}

郁闷!老错那个地方.................
#6
a6320340792009-12-22 15:46
原来#include <string.h>的.h是不要的啊!怪不得老错............
#7
秀痘魔导士2009-12-23 14:30
  string.h是旧式的C-Style  
  string是标准C++支持的,功能比C-Style强大很多。   

带.h的文件不支持名字空间,不带的支持名字空间
#8
秀痘魔导士2009-12-23 14:30
提个小建议,如果想求助,最好吧代码发上来,不然很容易误导。
1