Outils pour utilisateurs

Outils du site


lang:cpp:stream

Obtenir la taille d'un fichier via ifstream

Il faut forcer à se positionner à la fin du fichier.

std::ifstream file;
file.open(name,std::ios::in|std::ios::binary);
file.ignore( std::numeric_limits<std::streamsize>::max() );
std::streamsize length = file.gcount();
file.clear();
file.seekg( 0, std::ios_base::beg );

Using C++ filestreams (fstream), how can you determine the size of a file? Archive du 09/03/2010 le 16/08/2022

lang/cpp/stream.txt · Dernière modification : 2022/08/16 11:21 de root