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?

Recommended Answers

All 2 Replies

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

Worked fine! Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.