观洱 2022-01-24 12:49 采纳率: 50%
浏览 1590
已结题

[Error]no match for 'operator>>'(operand types are'std::basic_istream<char> and 'Point[20]'

想在txt文件中一行录入一个结构数组的数据,一项数据里面还包含了一个自己写的类的数组,在编写读入函数时出现了这个报错 [Error]no match for 'operator>>'(operand types are'std::basic_istream and 'Point[20]'

include<bits/stdc++.h>
include"SeqList.h"
include"Point.h"
using namespace std;

struct People{//人员信息 
        int no;//序号 
        bool health;//健康为1,感染为0
        string name;
        string address;
        string time;
        Point P[20];//活动地点 
};
void readData(ifstream &file,People& p)
{
    file>>p.no>>p.name>>p.health>>p.address>>p.P>>p.time;
}
int readPeoInfo(People peo[])
{
    ifstream fileB("PeopleData.txt"),fileA("PeopleData.txt");
    if (!fileB)
    {
        cout<<"没有找到需要读取的PeopleData.txt,请将文件放到指定位置再次运行本程序"<<endl<<"按任意键以退出";
        return -1;
    }
    char dustBin[500];
    int i,j;
    for (i = 0; !fileA.eof(); i+=2)
    {
        fileA.getline(dustBin,100);
        readData(fileA,peo[i]);
    }
    fileA.close();
    fileB.getline(dustBin,100);
    for(j=1;!fileB.eof();j+=2)
    {
        fileB.getline(dustBin,100);
        readData(fileB,peo[j]);
    }
    fileA.close();
    int count = i>j?i-2:j-2;
    return count;
}
typedef struct People People;
int main(){
    People a[50];//创建初始人群 
    int count = readPeoInfo(a);
    for(int i=0;i<count;i++)
    {
        cout<<a[i].no<<"      "<<a[i].name<<"     "<<a[i].health<<"     "<<a[i].address<<"     "<<a[i].P<<"     "<<a[i].time<<endl;
    }
}


```,不知道该怎么办,求解答
求解答Thanks♪(・ω・)ノ
  • 写回答

2条回答 默认 最新

  • CSDN专家-link 2022-01-24 13:04
    关注

    p.P不能直接 >>的
    你得给Point类增加>>操作符重载,<<操作符也需要

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 2月1日
  • 已采纳回答 1月24日
  • 创建了问题 1月24日

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置