I am writing a simple program to read in date from a lotto winning numbers file. The data is structured like this:
01/03/1998 6 - 12 - 20 - 33 - 34 - 50
01/10/1996 13 - 22 - 34 - 40 - 44 - 49
etc.
No matter how many records there are, the following code reports one record too many and reads the last number on the last date 7 times.
vector <string> dates; //to hold all the dates
string thisdate; //to hold the current date being read in
vector <int> numbers; //to hold all the numbers
int thisnumber; //to hold the number currently being read in
int count=0;
char dash; //will be used to get rid of the dashes between numbers
//read the lotto file, putting dates into 1 vector, and numbers into another
while(infile){
infile>>thisdate;
dates.push_back(thisdate);
for(int i=0;i!=5;i++){
infile>>thisnumber;
frequency[thisnumber-1]++;
numbers.push_back(thisnumber);
infile>>dash;
}
infile>>thisnumber;
frequency[thisnumber-1]++;
numbers.push_back(thisnumber);
count++;
}
cout<<"total number of lotto drawings was "<<count<<endl;
I believe the problem is somehow with while(infile), ie, I dont believe I understand exactly how it works. Any help will be greatly appreciated.