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

[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日

悬赏问题

  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败