0
std::vector<LogEntry> parse(std::istream& in) {
    std::vector<LogEntry> result;

    char c[500];
    LogEntry log;
    String entry;
    while(!in.eof()){
      in.getline(c, 500);
      if(in.eof())
        break;
      entry = String(c);
      log = LogEntry(entry);
      result.push_back(log);
    }
return result;
}

How do I change this parse function for it to work I have print out statements in my code and it stops at entry = String(c), our goal with this function is to use our String ADT we created and to read all the lines from the files that they give us and to create a logEntry object for each line. This function will return a vector of logEntry's.

  • What is `String`, what is `LogEntry` and how do you know that it stops at the line you mentioned? Please provide some more information. – Lukas-T Mar 05 '20 at 08:07
  • please provide a [mre] with sample input and exactly what the issue is that you are having – Alan Birtles Mar 05 '20 at 08:10
  • 2
    Probably beside the question, but you can clean up the end-of-file logic. See e.g. https://stackoverflow.com/questions/7868936/read-file-line-by-line-using-ifstream-in-c. No need to check EOF twice. – AVH Mar 05 '20 at 08:21
  • `while (in.getline(c, 500)` is a better loop. – molbdnilo Mar 05 '20 at 08:36
  • 1
    At a guess, `String` should obey "the rule of three (or five)" but doesn't. – molbdnilo Mar 05 '20 at 08:37
  • 1
    It looks like you could slim that down to `while (in.getline(c, 500)) { result.push_back(String(c)); }`. – molbdnilo Mar 05 '20 at 08:39

0 Answers0