0

I am trying to add a numbering system to a list in a datafile:

Appointments.open(DATAFILE);
  if (Appointments.is_open())
    {
    // Read the file until it's finished, displaying lines as we go.
    while (!Appointments.eof())
      {	
	  getline(Appointments, line, '\n'); // getline reads a line at a time
      appointment.push_back(line);
      cout << i << ". " << line << endl;
      i++;
      }

    Appointments.close();
    }

So the proper output should be:
1. 12 August 2010 Test
2. 13 August 2010 Test2

However the output comes out as:
1. 12 August 2010 Test
2. 13 August 2010 Test2
3.

How do I get rid of the extra 3?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by ksm092
1

[One option]
You can insert an if statement that makes sure the line length is greater than two before writing to the output file.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.