注册 登录
编程论坛 数据结构与算法

类型不兼容

编程吗 发布于 2018-11-29 23:53, 2777 次点击
struct Intersection {
    int left, forward, right;  //路口信息
};
typedef struct Maze {
    int MazeSize; //迷宫大小(路口数)
    int EXIT; //出口号码
    struct Intersection *intsec;  //路口数组
}mazestruct;
/*****************************************************/

/*****************************************************/
bool GetMaze(char *filename,mazestruct &M) {
    //读取迷宫数据:从文件filename 中读取各路口
   //和出口的数据
    ifstream fin;
    fin.open(filename, ios::in);
    //为输入打开文件,文件不存在则打开失败
    if (!fin) {
        cout << "迷宫数据文件" << filename << "打不开" << endl;
        return false;
    }
    fin >> M.MazeSize; //输入迷宫路口数
    M.intsec = new Intersection[M.MazeSize + 1];
    //创建迷宫路口数组
    for (int i = 1; i <= M.MazeSize; i++)
        fin >> M.intsec[i].left >> M.intsec[i].forward
        >> M.intsec[i].right;
    fin >> M.EXIT; //输入迷宫出口
    fin.close();
    return true;
}

int main() {
    Maze m;//struct maze m(区别);
    GetMaze("maze.txt",m);
    Traverse(1);
    return OK;
}

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

3 回复
#2
MeandC2018-12-05 13:27
不用C++,你用C写一下。把.c改成.cpp后碰到过这种类型报错。
#3
俺是你大爷2019-03-12 13:23
改成数组就是了
#4
qq17464127242019-03-22 15:26
确实
1