By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,195 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

Create a object passing the line just input

P: 43
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_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.


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:
Expand|Select|Wrap|Line Numbers
  1. std::vector<Log_Entry> parse(const string& filename)
  2. {
  3.      vector<Log_Entry> log_entries;
  4.      std::string line;
  5.      ifstream in_file(filename.c_str());
  6.      if(!in_file)
  7.      {
  8.          // couldn't open input file, exit                                     
  9.          cerr << "Error: couldn't open "
  10.               << filename
  11.               << " exiting\n";
  12.          exit(1);
  13.      }
  14.      while(!in_file.eof())
  15.      {
  16.          getline(in_file, line);
  17.  
  18.      }
  19.      in_file.close();
  20.      return log_entries;
  21. }
  22.  
  23.  
Jun 19 '08 #1
Share this Question
Share on Google+
1 Reply


gpraghuram
Expert 100+
P: 1,275
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
Jun 20 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.