C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

probleme avec ofstream

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
dark poulpo
Guest





PostPosted: Thu Aug 12, 2004 11:15 pm    Post subject: probleme avec ofstream Reply with quote



bonsoir,
voila jai creer un fichier avec

ofstream sortie(ff );
sortie.write( (char *) &f, sizeof(structure)); // operation refaite n fois,
les données dans la stucture sont des valeurs de 0 a 255, structure fait 256
octets
sorttie.close();
------------ et ensuite jessai de le lire: ---------

ifstream entree;
entree.open(ff);
if (!entree.is_open()) return;
....
while (entree.read((char *) &t, sizeof(structure)))


...
}
entree.close(); // fortement recommandé
-------------------------------------

mon probleme est que entree.read me lit les premiers 256 octets (la
structure), et sort irectement de la boucle, alors que le fichier fait plus
de 4Ko.
ca refuse donc de me lire la suite!!!!!!!

si quelqu'un peut m'aider,,, merci d'avance!!!!!



Back to top
Michel Michaud
Guest





PostPosted: Fri Aug 13, 2004 1:24 am    Post subject: Re: probleme avec ofstream Reply with quote



Dans news:cfgsmd$iiq$1 (AT) news-reader3 (DOT) wanadoo.fr, dark
poulpo <syn-ack (AT) wanadoo (DOT) fr> a écrit :
Quote:
ofstream sortie(ff );

Il faut ouvrir le fichier en mode binaire, ici :

ofstream sortie(ff, ios_base::binary);

Et là :
Quote:
ifstream entree;

ifstream entree(ff, ios_base::binary);

Quote:
entree.open(ff);

Pourquoi tu faisais ça en deux étapes ici ?

--
Michel Michaud [email]mm (AT) gdzid (DOT) com[/email]
http://www.gdzid.com
FAQ de fr.comp.lang.c++ :
http://www.cmla.ens-cachan.fr/~dosreis/C++/FAQ/


Back to top
dark poulpo
Guest





PostPosted: Fri Aug 13, 2004 6:36 am    Post subject: Re: probleme avec ofstream Reply with quote



"Michel Michaud" <mm (AT) gdzid (DOT) com> a écrit dans le message news:
MLUSc.26490$Mq1.1615392 (AT) news20 (DOT) bellglobal.com...
Quote:
Dans news:cfgsmd$iiq$1 (AT) news-reader3 (DOT) wanadoo.fr, dark
poulpo <syn-ack (AT) wanadoo (DOT) fr> a écrit :
ofstream sortie(ff );

Il faut ouvrir le fichier en mode binaire, ici :

ofstream sortie(ff, ios_base::binary);

Et là :
ifstream entree;

ifstream entree(ff, ios_base::binary);

entree.open(ff);

Pourquoi tu faisais ça en deux étapes ici ?

--
Michel Michaud [email]mm (AT) gdzid (DOT) com[/email]
http://www.gdzid.com
FAQ de fr.comp.lang.c++ :
http://www.cmla.ens-cachan.fr/~dosreis/C++/FAQ/

merci

je vais faire ca,
j'ouvre pas en 2 etapes, c'est parce que "plus loin" siginifie en fait "dans
une autre procedure (load et save)



Back to top
drkm
Guest





PostPosted: Fri Aug 13, 2004 1:49 pm    Post subject: Re: probleme avec ofstream Reply with quote

"dark poulpo" <syn-ack (AT) wanadoo (DOT) fr> writes:

Quote:
entree.close(); // fortement recommandé

Bof. Si tu ne testes pas si la fermeture s'est bien passée et que
tu n'as pas besoin d'une fermeture avant la fin de portée, je ne vois
pas trop l'intérêt.

De mémoire, pour tester la fermeture, je dirais :

if ( ! entree.rdbuf()->close() ) {
// erreur
}

si tu es certain que le fichier est ouvert, sinon :

if ( entree.is_open() && ! entree.rdbuf()->close() ) {
// erreur
}

--drkm, en recherche d'un stage : http://www.fgeorges.org/ipl/stage.html

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.