简体   繁体   中英

counting data in csv file that has 2 columns

I'm having trouble counting the number of elements in each column of a 2 column .csv file. I wrote a small code below but it's wrong and I'm not sure how to approach. Please advise! Thank you!

while(!inFile.eof()) //While the original file is open, the # of lines is counted.
{
    inFile>>datafile[i++][i++]; //this counts the data in each column
}
cout<<"The length of the original data file is "<<[i]<<[i]<<"."<<endl;

Assuming datafile is declared as something like this:

int datafile[256][2];

The first set of square brackets is for the row, and the second set of square brackets is for the column. (It could be the other way round.) And your variable i is counting which row you're inputting data to - it could be renamed row , in fact.

So you don't want to be putting i or row in the brackets which choose the column... is that enough to give you a foothold?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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