我遇到一个错误,在第61行上说open的左边必须有一个class / struct / union。我在第78行也有同样的错误。我在2013年的visual studio工作。我很困惑为什么我需要重新定义它是什么类。
#include <iostream>
#include <string>
#include <fstream>
#include <cctype>
using namespace std;
struct recordPlayer
{
string id, firstname, lastname, division, team;
int platApp, atBats, singles, doubles, triples, homers, sacks, walks, hitbyPitch;
double battingAvg, onBase, Slugging;
int totalHit, totalBases;
};
struct playerUpdate
{
string update;
string id, firstname, lastname, division, team;
int platApp, atBats, singles, doubles, triples, homers, sacks, walks, hitbyPitch;
float battingAvg, onBase, Slugging;
int totalHit, totalBases;
};
bool newPlay(char x);
bool delPlay(char x);
bool updatePlay(char x);
int playerId(string x, recordPlayer y[], int fileSize);
void equalThem(recordPlayer x[], playerUpdate y[], int location, int fileSizeTwo);
void deleteThem(recordPlayer x[], playerUpdate y[], int location, int fileSizeTwo);
void determineStats(recordPlayer x[], int fileSize);
ofstream& operator << (ofstream& outdata, recordPlayer data)
{
outdata << data.id << "/t" << data.firstname << "/t" << data.lastname << "/t" << data.division << "/t" << data.team << "/t" << data.platApp << "/t" << data.atBats << "/t" << data.singles << "/t" << data.doubles << "/t" << data.triples << "/t" << data.homers << "/t" << data.sacks << "/t" << data.walks << "/t" << data.hitbyPitch << "/t" << data.battingAvg << "/t" << data.onBase << "/t" << data.Slugging << endl;
return outdata;
}
ifstream& operator >> (ifstream& indata, recordPlayer data)
{
indata >> data.id >> data.firstname >> data.lastname >> data.division >> data.team >> data.platApp >> data.atBats >> data.singles >> data.doubles >> data.triples >> data.homers >> data.sacks >> data.walks >> data.hitbyPitch >> data.battingAvg >> data.onBase >> data.Slugging;
return indata;
}
ofstream& operator << (ofstream& outdata, playerUpdate upd)
{
outdata << upd.id << "/t" << upd.firstname << "/t" << upd.lastname << "/t" << upd.division << "/t" << upd.team << "/t" << upd.platApp << "/t" << upd.atBats << "/t" << upd.singles << "/t" << upd.doubles << "/t" << upd.triples << "/t" << upd.homers << "/t" << upd.sacks << "/t" << upd.walks << "/t" << upd.hitbyPitch << "/t" << upd.battingAvg << "/t" << upd.onBase << "/t" << upd.Slugging << endl;
return outdata;
}
ifstream& operator >> (ifstream& indata, playerUpdate upd)
{
indata >> upd.id >> upd.firstname >> upd.lastname >> upd.division >> upd.team >> upd.platApp >> upd.atBats >> upd.singles >> upd.doubles >> upd.triples >> upd.homers >> upd.sacks >> upd.walks >> upd.hitbyPitch >> upd.battingAvg >> upd.onBase >> upd.Slugging;
return indata;
}
int main()
{
recordPlayer stats[1000];
playerUpdate statsNew[1000];
ifstream statsOld;//stats2013
statsOld.open("Master_Data.csv");
ifstream statsNew;//stats 2014
statsNew.open("2014_League_Stats_v2.csv");
ofstream scores;
scores.open("report.txt");
//File One
int fileoneSize = 0;
statsOld >> stats[fileoneSize].id >> stats[fileoneSize].firstname >> stats[fileoneSize].lastname >> stats[fileoneSize].division >> stats[fileoneSize].team >> stats[fileoneSize].platApp >> stats[fileoneSize].atBats >> stats[fileoneSize].singles >> stats[fileoneSize].doubles >> stats[fileoneSize].triples >> stats[fileoneSize].homers >> stats[fileoneSize].sacks >> stats[fileoneSize].walks >> stats[fileoneSize].hitbyPitch >> stats[fileoneSize].battingAvg >> stats[fileoneSize].onBase >> stats[fileoneSize].Slugging;
while (!statsOld.eof())
{
fileoneSize++;
statsOld >> stats[fileoneSize].id >> stats[fileoneSize].firstname >> stats[fileoneSize].lastname >> stats[fileoneSize].division >> stats[fileoneSize].team >> stats[fileoneSize].platApp >> stats[fileoneSize].atBats >> stats[fileoneSize].singles >> stats[fileoneSize].doubles >> stats[fileoneSize].triples >> stats[fileoneSize].homers >> stats[fileoneSize].sacks >> stats[fileoneSize].walks >> stats[fileoneSize].hitbyPitch >> stats[fileoneSize].battingAvg >> stats[fileoneSize].onBase >> stats[fileoneSize].Slugging;
}
int fileSizeTwo = 0;
while (!statsNew.eof())
{
char updateTypeChar = statsNew.get(); //gets the first character from the line, a DNR character
if (newPlay(updateTypeChar)) //new player or CREATE
{
fileoneSize++;
statsNew[fileSizeTwo].update = updateTypeChar;
statsNew >> statsNew[fileSizeTwo].id >> statsNew[fileSizeTwo].firstname >> statsNew[fileSizeTwo].lastname >> statsNew[fileSizeTwo].division >> statsNew[fileSizeTwo].team >> statsNew[fileSizeTwo].platApp >> statsNew[fileSizeTwo].atBats >> statsNew[fileSizeTwo].singles >> statsNew[fileSizeTwo].doubles >> statsNew[fileSizeTwo].triples >> statsNew[fileSizeTwo].homers >> statsNew[fileSizeTwo].sacks >> statsNew[fileSizeTwo].walks >> statsNew[fileSizeTwo].hitbyPitch >> statsNew[fileSizeTwo].battingAvg >> statsNew[fileSizeTwo].onBase >> statsNew[fileSizeTwo].Slugging;
statsOld >> stats[fileSizeTwo].id >> stats[fileSizeTwo].firstname >> stats[fileSizeTwo].lastname >> stats[fileSizeTwo].division >> stats[fileSizeTwo].team >> stats[fileSizeTwo].platApp >> stats[fileSizeTwo].atBats >> stats[fileSizeTwo].singles >> stats[fileSizeTwo].doubles >> stats[fileSizeTwo].triples >> stats[fileSizeTwo].homers >> stats[fileSizeTwo].sacks >> stats[fileSizeTwo].walks >> stats[fileSizeTwo].hitbyPitch >> stats[fileSizeTwo].battingAvg >> stats[fileSizeTwo].onBase >> stats[fileSizeTwo].Slugging;
fileSizeTwo++;
}
if (updatePlay(updateTypeChar)) //returning player or UPDATE
{
statsNew[fileSizeTwo].update = updateTypeChar;
statsNew >> statsNew[fileSizeTwo].id >> statsNew[fileSizeTwo].firstname >> statsNew[fileSizeTwo].lastname >> statsNew[fileSizeTwo].division >> statsNew[fileSizeTwo].team >> statsNew[fileSizeTwo].platApp >> statsNew[fileSizeTwo].atBats >> statsNew[fileSizeTwo].singles >> statsNew[fileSizeTwo].doubles >> statsNew[fileSizeTwo].triples >> statsNew[fileSizeTwo].homers >> statsNew[fileSizeTwo].sacks >> statsNew[fileSizeTwo].walks >> statsNew[fileSizeTwo].hitbyPitch >> statsNew[fileSizeTwo].battingAvg >> statsNew[fileSizeTwo].onBase >> statsNew[fileSizeTwo].Slugging;
string pID = statsNew[fileSizeTwo].id;
int location = playerId(pID, stats, fileoneSize);
equalThem(stats, location, fileSizeTwo);
fileSizeTwo++;
}
if (delPlay(updateTypeChar)) //didnt return or DELETE
{
statsNew[fileSizeTwo].update = updateTypeChar;
stats >> statsNew[fileSizeTwo].id >> statsNew[fileSizeTwo].firstname >> statsNew[fileSizeTwo].lastname >> statsNew[fileSizeTwo].division >> statsNew[fileSizeTwo].team >> statsNew[fileSizeTwo].platApp >> statsNew[fileSizeTwo].atBats >> statsNew[fileSizeTwo].singles >> statsNew[fileSizeTwo].doubles >> statsNew[fileSizeTwo].triples >> statsNew[fileSizeTwo].homers >> statsNew[fileSizeTwo].sacks >> statsNew[fileSizeTwo].walks >> statsNew[fileSizeTwo].hitbyPitch >> statsNew[fileSizeTwo].battingAvg >> statsNew[fileSizeTwo].onBase >> statsNew[fileSizeTwo].Slugging;
string pID = statsNew[fileSizeTwo].id;
int whereItIs = playerId(pID, stats, fileoneSize);
deleteThem(stats, statsNew, whereItIs, fileSizeTwo);
fileSizeTwo++;
}
}
}
答案 0 :(得分:3)
您有statsNew
的两个相互矛盾的声明:
playerUpdate statsNew[1000];
ifstream statsNew;//stats 2014
答案 1 :(得分:1)
您的statsNew
定义了两次。一次作为playerUpdate
和第二列的数组 - 作为ifstream
。