大家看看这代码哪错了,改怎么改啊

来源:百度知道 编辑:UC知道 时间:2024/04/30 04:32:13
#include<iostream>
using std::string;
using std::cout;
using std::endl;

class GradeBook
{
public:
GradeBook(string name)
{
setCourseName(name);

}
void setCourseName(string name)
{
if(name.length()<=25)
courseName=name;

if(name.length()>25)
{
courseName=name.substr(0,25);

cout<<"name \""<<name<<\"dxceeds maximun length(25).\n"<<"limiting courseName to frist 25 characters.\n"<<endl;
}
}
string getCourseName()
{
return courseName;
}
void displayMessage()
{
cout<<"welcome to the grade book for\n"<<getCourseName()<<"!"<<endl;

}
private:
string courseName;
};

int main()
{
GradeBook gradebook1("cs101 introduction to programing

加一句
#include<string>
string是标准库里的,你得包含进来

还有一处错误
void setCourseName(string name) 的定义里最后一条语句
cout<<"name \""<<name<<\"dxceeds maximun length(25).\n"<<"limiting courseName to frist 25 characters.\n"<<endl;
改成(<<后面多了一个反斜杠)
cout<<"name \n"<<name<<"dxceeds maximun length(25).\n"<<"limiting courseName to frist 25 characters.\n"<<endl;