| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 477 人关注过本帖
标题:一个关于string的错误
只看楼主 加入收藏
zhangmohan28
Rank: 2
来 自:山西
等 级:论坛游民
帖 子:12
专家分:13
注 册:2010-8-27
结帖率:100%
收藏
已结贴  问题点数:0 回复次数:3 
一个关于string的错误
哥哥姐姐们帮忙看下这个程序该怎么修改  谢谢了
程序代码:
#ifndef COURSE_H
#define COURSE_H

#include <vector>
#include <string>
using namespace std;
class CCourse
{
public:
    Course(const string &courseName);
    string getCourseName();
    void addStudent(const string &student);
    string *getStudent();
    int getNumberOfStudents();

private:
    string m_scourseName;
    vector<string> v_sstudent;
    int m_inumberOfStudents;
};

#endif#include "CourseClass.h"
#include <iostream>
using namespace std;
CCourse::Course(const string &courseName)
{
    m_inumberOfStudents = 0;
    this->m_scourseName = courseName;
}

string CCourse::getCourseName()
{
    return m_scourseName;
}

void CCourse::addStudent(const string &student)
{
    v_sstudent.push_back(student);
    m_inumberOfStudents++;
}
string *CCourse::getStudent()
{
    return v_sstudent.begin();
}

int CCourse::getNumberOfStudents()
{
    return m_inumberOfStudents;
}#include "CourseClass.h"
#include <iostream>
using namespace std;
void main()
{

    CCourse course("Database");
    string stuName;
    bool flag = 1;
    while(flag)
    {
        cout<<"请输入添加学生的姓名:"<<endl;
        cin>>string stuName;
        course.addStudent(stuName);
        cout<<"继续加入学生? 是(1) 否(0)"<<endl;
        cin>>flag;
    }
    cout<<"本课堂的学生为"<<course.getCourseName()<<endl;
    cout<<"本课堂共有学生的人数为"<<course.getNumberOfStudents()<<endl;
    cout<<"检测通过"<<endl;
}
系统总是提示一些莫名其妙的错误
error C2664: '__thiscall CCourse::CCourse(const class CCourse &)' : cannot convert parameter 1 from 'char [9]' to 'const class CCourse &'
        Reason: cannot convert from 'char [9]' to 'const class CCourse'
error C2275:'string' : illegal use of this type as an expression
        c:\program files\microsoft visual studio\vc98\include\xstring(612) : see declaration of 'string'
搜索更多相关主题的帖子: string 
2010-10-23 10:17
m21wo
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:4
帖 子:440
专家分:1905
注 册:2010-9-23
收藏
得分:20 
怎么感觉你乱在贴啊!应该这么放!我也帮给你改了下!
程序代码:

CourseClass.h

#ifndef COURSE_H
#define COURSE_H

#include <vector>
#include <string>
using namespace std;
class CCourse
{
public:
    CCourse(const string& courseName);
    string getCourseName();
    void addStudent(const string &student);
    string getStudent();
    int getNumberOfStudents();

private:
    string m_scourseName;
    vector<string> v_sstudent;
    int m_inumberOfStudents;
};

#endif


CourseClass.cpp


#include "CourseClass.h"
#include <iostream>
using namespace std;
CCourse::CCourse(const string& courseName)  // 构造函数与类同名
{
    m_inumberOfStudents = 0;
    this->m_scourseName = courseName;
}

string CCourse::getCourseName()
{
    return m_scourseName;
}

void CCourse::addStudent(const string &student)
{
    v_sstudent.push_back(student);
    m_inumberOfStudents++;
}
string CCourse::getStudent()
{
    return *v_sstudent.begin();    // v_sstudent.begin()返回的是地址
}

int CCourse::getNumberOfStudents()
{
    return m_inumberOfStudents;
}

void main()
{

    CCourse course("Database");
    string stuName;
    bool flag = 1;
    while(flag)
    {
        cout<<"请输入添加学生的姓名:"<<endl;
        cin>>stuName;                             // 怎么还在输入前加类型
        course.addStudent(stuName);
        cout<<"继续加入学生? 是(1) 否(0)"<<endl;
        cin>>flag;
    }
    cout<<"本课堂的学生为"<<course.getCourseName()<<endl;
    cout<<"本课堂共有学生的人数为"<<course.getNumberOfStudents()<<endl;
    cout<<"检测通过"<<endl;
}


If You Want Something, Go Get It, Period.
2010-10-23 10:36
zhangmohan28
Rank: 2
来 自:山西
等 级:论坛游民
帖 子:12
专家分:13
注 册:2010-8-27
收藏
得分:0 
回复 2楼 m21wo
谢谢~问题解决了~可是不知道怎么给你分~告下怎么给分~
2010-10-23 12:55
m21wo
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:4
帖 子:440
专家分:1905
注 册:2010-9-23
收藏
得分:0 
呵呵!贴子右上边结贴就ok 了!

If You Want Something, Go Get It, Period.
2010-10-23 13:47
快速回复:一个关于string的错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016559 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved