vector 容易包含自定义类型 的错误,请求大家帮忙。
#include "stdafx.h"
#include "iostream"
#include <ostream.h>
#include <istream.h>
#include <vector>
//using std::cout;
//using std::endl;
//using namespace std;
class student
{
public:
student(int s)
{
score=s;
}
int getpoint() const
{
return score;
}
void setpoint(int k)
{
score=k;
}
student(const student &rhs)
{
this->score=rhs.getpoint();
}
student& operator=(const student &rhs)
{
if (this->score==rhs.getpoint())
return *this;
else
{
this->score=rhs.getpoint();
}
return *this;
}
public:
friend bool operator==(const student &lhs,const student &rhs)
{
int g=rhs.getpoint();
int j=lhs.getpoint();
if(g==j)
return true;
else
return false;
}
friend ostream& operator<<(ostream &os,const student &rhs)
{
os<<rhs.getpoint();
return os;
}
friend istream& operator>>(istream &in, student &rhs)
{
int h;
in>>h;
if(in)
{
rhs.setpoint(h);
}
return in;
}
private:
int score;
};
int main(int argc, char* argv[])
{
vector<student> vec; //
cout<<"please input a score"<<endl;
student input(10);
while(cin>>input)
{
}
return 0;
}
发生的错误提示:error C2065: 'vector' : undeclared identifier
D:\vc\s\s.cpp(93) : error C2275: 'student' : illegal use of this type as an expression
D:\vc\s\s.cpp(13) : see declaration of 'student'
D:\vc\s\s.cpp(93) : error C2065: 'vec' : undeclared identifier