简体   繁体   English

用C ++读取文件。 没有班级/结构/联盟

[英]C++ reading in Files. No Class/Struct/Union

I am having an error that says on line 61 that left of open must have a class/struct/union. 我遇到一个错误,在第61行上说,打开的左边必须有一个class / struct / union。 I also have the same error on line 78. I am working in visual studio 2013. I am confused on why I need to redefine what class it is. 我在第78行上也有同样的错误。我在Visual Studio 2013中工作。我对为什么需要重新定义它的类感到困惑。

#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++;
        }
    }
}

You have two conflicting declarations of statsNew : 您有两个相互矛盾的statsNew声明:

playerUpdate statsNew[1000];

ifstream statsNew;//stats 2014

Your statsNew is defined twice. 您的statsNew定义了两次。 Once as array of playerUpdate and second - as ifstream . 一次作为playerUpdate数组,第二次作为ifstream

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM