Blue Sky
Blue Sky

Reputation: 29

Printing an entire text file without showing the blank lines, c++

How can I print and entire text file in c++ without showing the blank lines between entries. for example I have a text which contains the data below :

ID: 01   FName: Andy   Lname: Garcia 
//this line is left blank
//this line is left blank
//this line is left blank
ID: 02   FName: Brad   Lname: Pitt 

Now I want to print the entire text file and I usually use while loop for that. But this time I want the program to skip these blank lines. One of the reasons why I want this to happen is that, I have separated the eateries by adding a : "Next" << endl; , this "Next" appears after each line when the program prints out the file but because there are so many blank line, it also prints so many Next one after another.

I would really appreciate any instructions. Thank you

Upvotes: 1

Views: 281

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 755094

The necessary code is simple:

  • Read each line (in a while loop)
  • Before printing the line, test whether it is empty; only print if it is not empty.

Upvotes: 4

Related Questions