Code:
#include <iostream>
#include <conio.h>
using std::string;
using std::cout;
using std::endl;
class GradeBook
{
public:
GradeBook(string name)
{
setCourseName(name);
}
void setCourseName(string name)
{
courseName= name;
}
string getCourseName()
{
return courseName;
}
void displayMessage()
{
cout << "Welcome to the grade book for\n" << getCourseName()
<< "!" << endl;
}
private :
string courseName;
};
int main()
{
GradeBook myGradeBook("Lap trinh C++");
getche();
return 0;
}
Lỗi : c:\documents and settings\administrator\my documents\visual studio 2005\projects\classes2005\classes2005\main.cpp(25) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
Em code bên Dev-C thì chạy bình thường, nhưng khi chuyển qua VS 2005 thì bị lỗi trên.