this is the part i was trying to implement unsuccesfully:
Code:string t; int lineCount=0; while(getline(file_op, t, '\n')) ++lineCount; cout << "The number of lines in the file is " << lineCount << endl;
this is the part i was trying to implement unsuccesfully:
Code:string t; int lineCount=0; while(getline(file_op, t, '\n')) ++lineCount; cout << "The number of lines in the file is " << lineCount << endl;
i got it ...thanx =)
Here's what I whipped up:
Oh.. were you trying to write to outfile.txt your results?Code://#include "stdafx.h" #include <fstream> #include <iostream> using namespace std; void countLines( istream& in, int& lines ) { char val = '\0'; lines = 0; while ( in.get( val ) ) { if ( val == '\n' || val == '\r' ) lines++; } } int main( int argc, char* argv[] ) { fstream file_op( "andop.txt", ios::in ); int lines; countLines( file_op, lines ); cout << "Lines: " << lines << endl; return 0; }
I see you got it.. post it!
oh well i got the part for reading the number of lines... I just modified the small code I typed...however i couldnt display it properly on the output file...but I just thought it was enough bugging you guys...jeje