I have an input file with lines in different formats.
**************************************************************
Sample of Input File:
Matthew Alan Aberegg 1978 Account$: 452,627
Adams, William Logan 1957 50,767
Siyabi, Mohamed born: 1970 790,183
Sulaiman, Yasser 1951 696,311
Barnett, Alan Christopher 1976 Account$: 83,736
Catherine P Baugher 1979 552,067
**************************************************************
I need to look at the date and if they are sixty or older print out "ready" at the end of the line.
I've been working on this for hours and I can't figure it out. It will produce a blank output file, all the numbers together or print out only the first line. How can I get it to read the numbers correctly? (i.e. as a four digit number) so I can compare it to 1956 which is the most recent birth date that would have "ready" printed at the end of its line.
************************************************************************
Sample Program:
First suggestion. Since the data in the file is arranged in separate lines, then read it line by line.
1 2 3 4 5 6 7
ifstream input("data.txt");
string line;
while (getline(input, line))
{
cout << line << '\n';
}
Second suggestion. Use a stringstream to parse the data within the line.
1 2 3
std::istringstream ss(line);
int year = 0;
ss >> year;
This fragment shows how to read an integer from the line. However - that is only a start. In practice there are several names or words which precede the year within the line.
There are lots of different ways to do this, You could for example read character-by-character until a digit is found, then use the putback() function to replace that digit into the stringstream where you got it from, and then read the year using ss >> year.
Another approach would be use a loop. Keep trying until either the year has been read, or the stream is empty. If the read of the integer failed, try to read a string instead. Hint, you will need to clear() the error flags after a failed read of the integer.
Those are just ideas of course. You may have others.
read every char until you find a 1 or 2, if you find a 2 go to next line
if you find 1, check next number to see if it's > 5, if yes check next to see if it's > 6.
if you want a 4 digit year read them all and put together with + symbol.