Nom de fichier

Résolu
dacor Messages postés 40 Date d'inscription mercredi 10 mai 2006 Statut Membre Dernière intervention 5 juin 2008 - 15 mai 2007 à 17:00
dacor Messages postés 40 Date d'inscription mercredi 10 mai 2006 Statut Membre Dernière intervention 5 juin 2008 - 16 mai 2007 à 14:11
bonjour,
comment pourai je connaitre la taille d'un fichier en c++ sous linux( à partir de son nom ex : /home/user/file.txt ).

merci de votre aide

3 réponses

SAKingdom Messages postés 3212 Date d'inscription lundi 7 novembre 2005 Statut Membre Dernière intervention 16 février 2009 15
15 mai 2007 à 22:53
En C (stdlib)
FILE *file = fopen("nomfichier", "r");
fseek(file, 0, SEEK_END);
taille = ftell(file);
fseek(file, 0, SEEK_SET);
fclose(file);

En C++ (STL je crois), je crois que c'est:
ifstream file("nomfichier", ios::binary);
file.seekg(0, io_base::end);
taille = file.tellg();
file.seekg(0, io_base::beg);

C++ (@++)<!--
3
cs_Matt67 Messages postés 549 Date d'inscription samedi 6 septembre 2003 Statut Membre Dernière intervention 6 mars 2010 3
15 mai 2007 à 20:10
Bonsoir,

man 2 stat...

Matt...
0
dacor Messages postés 40 Date d'inscription mercredi 10 mai 2006 Statut Membre Dernière intervention 5 juin 2008
16 mai 2007 à 14:11
merci
0
Rejoignez-nous