counting no. of new lines in input file

Hi everyone,

I am trying to count the number new lines, '\n', in an input file that i am reading using getline(). I think that when you use getline(), the newline character gets overwritten by a NULL character ( '\0'). So how would you count the number of newlines


1
2
3
4
5
6
7
8
	while (!read.eof())
	{
		
		read.getline(str,100,'\n');
	
		out<<str<<endl;  //print the lines to the output file as i get them 

}


Thanks in advance
Last edited on
closed account (zb0S216C)
getline( ) stops at a newline, right? So why not count every successful getline( ) invocation? It's just a idea, but maybe something like this:

1
2
3
4
for( int Line( 0 ); !read.eof( ), ++Line )
{
    // ...
}


Wazzak
Last edited on
Topic archived. No new replies allowed.