c++ - 转换结构时出错

标签 c++ function struct compiler-errors

我正在尝试读取海量姓氏和ssn的庞大数据集。当我尝试指向我的结构时,它说它正在尝试将我的single_info结构从personalf转换为singleinfo ...

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

struct single_info {
   string firstnames[6000];
   string lastnames[6000];
   string socialsecurity[6000];
   double gpa;
};

void ScanInFile(istream &, struct single_info, int *total);
void Outputfile(ostream &, struct single_info, int *total);

这是我的结构

这是我的函数,由于某些原因,我会出错:无法将“&personalf”从“single_info *”转换为“single_info”
void ScanInFile(istream &inputfile, struct single_info *individualf, int *total)
{
        int i=0;

   while(!inputfile.eof()){
      inputfile >> individualf->socialsecurity[i];
      inputfile >> individualf->firstnames[i];
      inputfile >> individualf->lastnames[i];
      i++
   }

      *total = i;
}

void Outputfile(ostream &outputfile, struct single_info *individualf, int *total)
{
   for(int i=0; i < *total; i++){
      outputfile << individualf->socialsecurity[i];
      outputfile << individualf->firstnames[i];
      outputfile << individual->lastnames[i];
   }

   outputfile << endl;
}

最佳答案

问题在于ScanInFileOutputfile的声明说他们将struct single_info作为其参数类型。看起来您的意思是struct single_info*(将与您的定义匹配)。任何试图调用您的函数的代码都只能看到声明,并试图传递single_info*,即使它仅要求single_info

请注意,在C++中,不需要将struct放在结构标识符之前。

关于c++ - 转换结构时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21518029/

相关文章:

c++ - 创建 OpenGL 2D View 相机,但使用模型 View 投影相机

php - 检查用户名是否存在,如果存在则生成新用户名 PHP

JSON 解码器忽略结构字段标签?

c++ - 变量 ' ' 周围的堆栈已损坏

c++ - QT 在单独的线程中管理 OpenGL 上下文

function - 替换 lisp 中的元素

templates - 如何将一片结构传递给模板并在 Golang 中迭代它们?

c - 如何按花色和值(value)创建有序的纸牌链表

c++ - 创建一个将字符串常量返回给枚举的类的廉价方法,反之亦然?

ios - 延迟更改 UIImageView.image