Hi guys, I have used this site for over a year now, it has helped me so much!
but i cant seem to find any information on this topic:
I am reading data from a text file and storing it as interger variables, I want to make my program "more defensive" and check to make sure all required data is present before computing anything.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
ifstream stream1;
stream1.open("K:\\test.txt");\\Desktop\\stocks.txt
if(!stream1)
{
cout<<"ERROR: File Not Found"<<endl;
}
while (stream1.good() )
{
//read file
stream1 >> a >> b >> c >> d >> e;
I problem I am having is making the program identify missing data for example if variable a is missing, the program just takes b, knocking everything out of sync.
All i have come up with so far is individual constraints for each variable, but these also fail when a "fitting" variable replaces the missing one.
It looks like you could use the whitespace as hinting. All the data is numeric, so short of custom-making a parser to parse the "right" kind of number data that would be the only approach.
Require tabs in-between column 1-2 and 4-5. You could do it something like this:
1 2 3 4 5 6 7
getfirstcolumn();
if (getcharacter() != '\t')
//problem???
getdatecolumn();
if (getcharacter() != '\t')
//u mad parser???
getthirdcolumn();