Create a object passing the line just input

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joestevens232
    New Member
    • Oct 2006
    • 43

    Create a object passing the line just input

    I'm stuck on how I can creat a LE object and pass it the line just input..than could i use a for loop and the .push_back to get the lines into the vector?

    vector<Log_Entr y> 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.


    I'm unsure on how I'm going to create a Log_Entry object and pass the line just input...

    Here is what I have so far:
    Code:
    std::vector<Log_Entry> parse(const string& filename)
    {
         vector<Log_Entry> log_entries;
         std::string line;
         ifstream in_file(filename.c_str());
         if(!in_file)
         {
             // couldn't open input file, exit                                     
             cerr << "Error: couldn't open "
                  << filename
                  << " exiting\n";
             exit(1);
         }
         while(!in_file.eof())
         {
             getline(in_file, line);
    
         }
         in_file.close();
         return log_entries;
    }
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    After reading the contents from the file how are you creating the onject which should be pushed to the vector.?
    And you return the vector by value which will be destryed as the fuction call stack gets cleared.
    So pass the vector as argument to the function by refernce andpopulate it.

    Raghu

    Comment

    Working...