Hi guys, I am trying to figure out how to set up two dimension arrays. I might not be using the right terms but i have 7 columns and a few hundred rows. What I am trying to do is compare the columns and two rows at a time. So comparing row 1 column 1 with row 2 column 1, then would cout if it doesnt fit into the argument. Then move to compare row 2 column 1 with row 3 column 1 and so on... How can I do so? Below is the example of data i will be using. Thanks.
The programming problems are:
1) while (!indata.eof())
2) pcolA is recreated for every line and given an indeterminate value
3) indata >> colA >> colB >> colC >> colD >> colE >> colF >> colG; requires whitespace separators by default, but you have comma separators
fixing those gives
1 2 3 4 5 6 7 8 9 10 11 12
ifstream indata("Test.csv");
unsignedlong pcolA = 0;
string line;
while (getline(indata, line))
{
unsignedlong colA;
istringstream(line) >> colA;
ofstream gaps("Rec.txt");
if( abs(colA - pcolA) > 5 && pcolA > 0)
gaps << "Gap in days at " << colA << '\n';
pcolA = colA;
}
But there is an error in the algorithm as well: subtracting *dates* in YYYYMMDD format does not exactly give the difference in *days*: 19971001 - 19970930 == 71, not 1. Consider parsing dates as actual dates, using a suitable library (try boost if you can, or if your compiler is sufficiently modern to have C++11's std::get_time in <iomanip>, use that)