I am writting a program that has three different files and is compiled by a Makefile. The goal is to take a file of text and split it up in different sections and stored in vectors. Then it outputs the information in a standard format. The main is fine and my function declarations are good also I am just having trouble writing the functions. Below are the function names and what they need to do. I have been trying some different ways to write the code and I keep coming up with errors I am new at c++. I will also attach the code I have so far if any can help point me in the right direction.
Log_Entry create_Log_Entry(const string&);
This function does the following:
The parameter is a log entry line.
Create a Log_Entry object.
Break the line into fields and subfields using split(). Several splits will be necessary.
Fill the data members with values.
Split on ' ' (space character) first, if the split does not give 10 strings set the number of bytes to 0 and return. (Some lines in the file may be bad.)
For string to int conversion use string streams.
vector<Log_Entry> parse(string);
This function does the following:
Open a log file specified by the parameter name (File I/O).
Read lines from the opened file.
Create a Log_Entry object passing the line just input.
Push each Log_Entry object onto a vector.
Return the vector of Log_Entrys.
void output_all(const vector<Log_Entry> &);
This function does the following:
Loop through the vector provided as the argument and output all information for each Log_entry object.
Format the output neatly in some manner, example output.
int byte_count(const vector<Log_Entry> &);
This function does the following:
Loop through the vector provided as the argument and sum the number_of_bytes members. The sum is returned.
void output_hosts(vector<Log_Entry>);
This function does the following:
Loop through the vector provided as the argument and output the host member of each Log_Entry object in the vector one per line.
vector<string> split(const string&, char);
This function does the following:
Takes a character parameter, uses the character as a separator in the string, and returns a vector of strings.
Ex. If the split function is given "abc:12345:xx" and ':' it will return a vector of 3 strings: "abc", "12345", and "xx".
One approach, a loop goes through the string, if the current character is not the splitter accumulate it into a string using string += char, if the current character is the splitter then push_back the string that holds the accumulated characters and clear the accumulator string variable.
There is a test function for split that can be run from the makefile. To run, for example:
./split abcx24567xqqq x
./split "abc 24567 qqq" " "