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

求助,这个错误我不知道 illegal, left operand has type 'char [10]'

林家的姑娘 发布于 2016-10-16 19:33, 3055 次点击
illegal, left operand has type 'char [10]'
这个错误说的是什么意思?
百度了也说比清楚

Teacher::Teacher(char n[10], char s[2])//构造函数
{
    name[10]=n[10];
    sex[2]=s[2];

    cout<<"名字:"name<<":"<<"编号:"<<num<<endl;
}
4 回复
#2
yangfrancis2016-10-16 22:19
Teacher::Teacher(char*n,char*s)
{
    strcpy(name,n);
    strcpy(sex,s);
    cout<<"名字:"<<name<<endl;
}
这样看行不行,猜的
#3
鸿蒙之灵2016-10-17 11:38
你没有整个工程的代码,只有这么一小段,我不知道你要实现什么,所以给你下面这段代码,供你参考:

程序代码:

#include <iostream>
#include <string>
using namespace std;

class Teacher
{
public:
    string name;
    string sex;
public:
    Teacher(string name,string sex):name(name),sex(sex){}
    const string& getName()
    {
        return name;
    }
    const string& getSex()
    {
        return sex;
    }
    void show()
    {
        cout<<"The teacher is :"<<name<<"    and his sex is:"<<sex<<" !"<<endl;
    }
};


#include "stdafx.h"
#include "stdlib.h"
#include "Teacher.h"

int _tmain(int argc, _TCHAR* argv[])
{
    Teacher teacher("王老师","00125425");
    teacher.getName();
    teacher.getSex();
    teacher.show();
    system("pause");
    return 0;
}


最后打印结果如下:

只有本站会员才能查看附件,请 登录


[此贴子已经被作者于2016-10-17 11:39编辑过]

#4
林家的姑娘2016-10-18 22:54
回复 2楼 yangfrancis
还是有点问题
不过,谢谢了
#5
林家的姑娘2016-10-18 22:55
回复 3楼 鸿蒙之灵
谢谢
1