Right now I am doing this with C++ 11:
long long int linecount;
fileifstream.open( filepath );
if( std::getline( fileifstream, newline ) )
{
linecount += 1;
// do some stuff with line and throw it out
}
fileifstream.close();
I would try to use this C getline()
but it is not available under Windows/Cygwin:
FILE * ifile = fopen( filename, "r" );
size_t linesz = 0;
char * line = nullptr;
unsigned int linecount = 0;
while( getline( &line, &linesz, ifile ) > 0 )
{
linecount++;
// do some stuff with line and throw it out
}
free( line );
std::cout << "Lines count: " << linecount << std::endl;
fclose(ifile);
Related:
- https://codereview.stackexchange.com/questions/115744/c-stack-implementation-using-stdlist
- std::ifstream in binary mode and locale in C++
- https://codereview.stackexchange.com/questions/119219/c-getline-implementation
- Performance difference of getline operating with istream and FILE*
Aucun commentaire:
Enregistrer un commentaire