0

Currently reading in a file with about 42,000 records in it. Although my vectors seem to always come up with 21,000. Going through debugging it seems to be skipping duplicate values. Like in the data example, there are 3 59's in column three. The run through input only has one then goes to 58.

Data Example:
20070906_NO@IND 1   59  55  IND NO  1   10  68
20070906_NO@IND 1   59  49  IND NO  2   10  68
20070906_NO@IND 1   59  15  IND NO  3   3   61
20070906_NO@IND 1   58  55  IND NO  3   8   66
20070906_NO@IND 1   58  49  IND NO  4   8   66


{
ifstream infile;
infile.open ("2007.csv");

while (infile.fail())
{
    cout << "Invalid File Name, Please Try Again. /n Filename: ";
    cin >> FileName;
    infile.open(FileName);
}

while(!infile.eof())
{       
    while (getline(infile,STRING, '\n'))
    {
        infile.ignore(',', ',');
        getline(infile,tempQuarter, ',');
        getline(infile,tempMinuteRemaining, ',');
        infile.ignore(',', ',');
        getline(infile,tempOffenseName, ',');
        getline(infile,tempDefenseName, ',');
        getline(infile,tempDown, ',');
        getline(infile,tempYardToGo, ',');
        getline(infile,tempNextYardLocation, ',');      

                    //Assign data to Vectors
        AssignToVector(tempQuarter,tempMinuteRemaining,tempOffenseName, tempDefenseName, tempDown, tempYardToGo, tempNextYardLocation, tempPlayDescription);
    }
}
cout << "Reading Completed"<<endl;  
infile.close(); 

}

4

1 回答 1

3

You have this:

while (getline(infile,STRING, '\n'))

which reads one line into STRING

then this:

{
    infile.ignore(',', ',');
    getline(infile,tempQuarter, ',');
    getline(infile,tempMinuteRemaining, ',');
    infile.ignore(',', ',');
    getline(infile,tempOffenseName, ',');
    getline(infile,tempDefenseName, ',');
    getline(infile,tempDown, ',');
    getline(infile,tempYardToGo, ',');
    getline(infile,tempNextYardLocation, ',');      

which reads a bunch of fields separated by commas.

The result, as far as I can see, is that every other line is read into STRING, and every other into tempXxx fields.

Did perhaps mean to do something like:

stringstream ss(STRING);
ss.ignore(100, ',');
getline(ss, tempQuarter, ',');
... 
于 2013-09-02T18:42:04.070 回答