Want to ask how to detect new line

For example, I need to read in a text file in this format

John 123 Y 1
abc
def
ghi

Jane 456 N 1
xyz

Jack 789 N 1
xxx
xxx

how do i detect the empty line and read in the next line?
i need to get the info for line 1, 6 and 9 only

Recommended Answers

All 2 Replies

When you call getline() it will return an empty string when there is an empty line.
Example:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
    string line;
    ifstream in("stdafx.h");
    if( in.is_open() )
    {
        while( getline(in,line) )
        {
            if( line == "")
                cout << "Empty line\n";
        }
    }
            

}

great, will try it out

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.