C++ 转换结构时出错
我试图读入一个巨大的数据集,包括姓氏、名字和ssn。当我试图指向我的结构时,它说它试图将我的单信息结构从individualf转换为单信息C++ 转换结构时出错,c++,function,struct,compiler-errors,C++,Function,Struct,Compiler Errors,我试图读入一个巨大的数据集,包括姓氏、名字和ssn。当我试图指向我的结构时,它说它试图将我的单信息结构从individualf转换为单信息 #include<iostream> #include<fstream> #include<cstdlib> #include<string> using namespace std; struct single_info { string firstnames[6000]; string las
#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);
#包括
#包括
#包括
#包括
使用名称空间std;
结构单_信息{
字符串名[6000];
字符串lastnames[6000];
字符串社会安全[6000];
双gpa;
};
void ScanInFile(istream&结构单一信息,整数*总计);
void Outputfile(ostream&,struct single_info,int*total);
这是我的结构
以下是我的函数,由于某些原因,我得到错误:无法将“&individualf”从“single\u info*”转换为“single\u 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;
}
void ScanInFile(istream&inputfile,结构单一信息*individualf,整数*total)
{
int i=0;
而(!inputfile.eof()){
输入文件>>个人F->社会安全[i];
输入文件>>个人F->名字[i];
inputfile>>individualf->lastnames[i];
我++
}
*总数=i;
}
void Outputfile(ostream&Outputfile,结构单一信息*individualf,int*total)
{
对于(int i=0;i<*总计;i++){
输出文件社会安全[i];
输出文件名[i];
输出文件lastnames[i];
}
outputfile问题是ScanInFile
和outputfile
的声明表示它们将struct single\u info
作为参数类型。看起来您的意思是struct single\u info*
(这与您的定义相匹配)。任何试图调用函数的代码都只能看到声明,并且试图传递一个single\u info*
,即使它只要求一个single\u info
< P>注意,在C++中不需要结构标识符之前,将Stult .< /P> < P>是的,它是原型。它需要像函数本身一样精确定义。在我的主程序之前的声明或函数定义之前的原型?@在您的问题中的第一段代码中,USER 307885。ScanInFile
和Outputfile
的声明。每个的第二个参数不是指针。while(!inputfile.eof()){
Whoops。。。