| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 2839 人关注过本帖
标题:error C2106: “=”: 左操作数必须为左值 求解!
取消只看楼主 加入收藏
学c艹的废柴
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2019-7-28
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
error C2106: “=”: 左操作数必须为左值 求解!
本人c++菜鸟,我编了一个结构体

程序代码:
struct teacher
{
    char name[9],title[7];
    teacher* next;
};


定义了一个变量 teacher head;

并给 head.hext=NULL;

然后我又 head.next= new teacher;

结果就显示了上面的报错    1>e:\ropes\linked_list\linked_list\linked_list.cpp(43): error C2106: “=”: 左操作数必须为左值

本人用的是vs2017,不知道这是怎么回事,请大家帮帮忙!

2019-07-28 23:16
学c艹的废柴
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2019-7-28
收藏
得分:0 
回复 2楼 rjsp
这是我的代码,我想做一个类似链表的东西,能随时添加新的“教师”,我自认为我的代码可以实现这个功能,但是不可以,请您帮我看看

程序代码:
#include <iostream>
#include<conio.h>
#include<string.h>
using namespace std;
struct teacher
{
    char name[10], title[7];
    teacher *next;
};
teacher find(teacher head)
{

    if (head.next == NULL)
        return head;
    else
        find(*(head.next));
}
int main()
{
    teacher head ;
    head.next = NULL;
    strcpy_s(head.name, "spname");
    strcpy_s(head.title, "stitle");
    while (true)
    {
        cout << "是否要添加教师?(y/n)";
        char c;
        char name[10], title[7];
        c = _getch();
        if (c == 'y' || c == 'Y')
        {
            teacher* tem;
            find(head).next = tem;
            cout << "教师的姓名是?\n";
            cin >> name;
            cout << "教师的职称是?\n";
            cin >> title;
            strcpy_s(find(head).next->name, name); strcpy_s(find(head).next->title, title);
            find(head).next->next = NULL;
            cout << "添加成功!";
        }
        else break;
    }
}
2019-07-29 09:48
快速回复:error C2106: “=”: 左操作数必须为左值 求解!
数据加载中...
 
   



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

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014917 second(s), 9 queries.
Copyright©2004-2025, BC-CN.NET, All Rights Reserved