having trouble understanding how to use parse

so i need to write a program that creates a struct and then opens a file reads it and stores all the data in an array of structs and then displays the data but i need to use parsing to look for errors.
here is the assignment in question

When parsing the file, look for the following kinds of problems:

Timestamps that begin with characters.
Timestamps that are less than 1,000,000,000.
Timestamps that are greater than 10,000,000,000.
Lines that are missing filenames, usernames, or timestamps (i.e., only have 2 items instead of 3).

Create a function, parseLine that accepts a line (a string) and populates a struct for the AccessRecord.
Create a function, parseFile, that parses the file one line at a time and passes that line to your parseLine function.
If an error occurs, in the parseLine function, throw an exception that is a string with the text: "Error parsing line: xxxx xxxx xxxx" (where xxxx xxxx xxxx is replaced by the actual text of the line that had the error).
In the parseFile function, catch any errors, display the message, and move on to the next line.

here is my code.

#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
using namespace std;

/**********************************************************************
*this sets up the struct called AccessRecord
***********************************************************************/
struct AccessRecord
{
string username;
string file;
long timestamp;
};

/**********************************************************************
*this prompts the user for a file
***********************************************************************/
string getFile()
{
string file;
cout << "Enter the access record file: ";
cin >> file;

return file;
}

/**********************************************************************
*this reads the file into the array of structs
***********************************************************************/
int loadFile(AccessRecord digitalfiles[], long &startTime, long &endTime)
{

string filename = getFile();
ifstream fin(filename.c_str());
if (fin.fail())
{
cout << "Please try again.";
return -1;
}
cout << "\n";
cout << "Enter the start time: ";
cin >> startTime;
cout << "Enter the end time: ";
cin >> endTime;

int count = 0;

while (fin >> digitalfiles[count].file
>> digitalfiles[count].username
>> digitalfiles[count].timestamp)
count++;

fin.close();
return count;
}

/**********************************************************************
*This displays the info in the array of structs
***********************************************************************/
void display(AccessRecord digitalfiles[], long startTime,
long endTime, int count)
{
cout << "\n";
cout << "The following records match your criteria:" << endl;
cout << "\n";

cout << setw(16) << "Timestamp " << setw(20) << "File " << setw(20)
<< "User\n";
cout << "--------------- ------------------- -------------------\n";

for (int i = 0; i < count; i++)
{
if (digitalfiles[i].timestamp >= startTime &&
digitalfiles[i].timestamp <= endTime)
{
cout << setw(15) << digitalfiles[i].timestamp
<< setw(20) << digitalfiles[i].file
<< setw(20) << digitalfiles[i].username << endl;
}
}
cout << "End of records" << endl;
}

/**********************************************************************
*this delegates to all the other function
***********************************************************************/
int main()
{
long startTime;
long endTime;
int count = 0;
AccessRecord digitalfiles[500];
count = loadFile(digitalfiles, startTime, endTime);
display(digitalfiles, startTime, endTime, count);
return 0;
}
You have been instructed to make a function, parseFile, that will feed the contents of a file one line at a time to a function parseLine.

You have been instructed to make a function, parseLine, that accepts a string.

Where are those functions? Make them
OP: what does your input file look like?
Topic archived. No new replies allowed.