PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > write
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
write

Réponse
 
LinkBack Outils de la discussion
Vieux 07/12/2007, 03h00   #1
Art Cummings
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut write

Hello all,

does the write function have a return type? I've got a write statement that
isn't writing and I wanted to see if there is a way to do error checking.

Thanks

Art

student.write(reinterpret_cast<char *>(&studentInfo),sizeof(studentInfo));


  Réponse avec citation
Vieux 07/12/2007, 09h46   #2
Kai-Uwe Bux
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: write

Art Cummings wrote:

> does the write function have a return type?


The write function from basic_ostream returns a basic_ostream&.


> I've got a write statement
> that isn't writing and I wanted to see if there is a way to do error
> checking.


The returned reference refers to the stream and you could check the flags.


> student.write(reinterpret_cast<char *>(&studentInfo),sizeof(studentInfo));


"student" is a rather peculiar name for a stream.



Best

Kai-Uwe Bux



  Réponse avec citation
Vieux 07/12/2007, 09h53   #3
Rolf Magnus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: write

Art Cummings wrote:

> Hello all,
>
> does the write function have a return type?


What write function?

> I've got a write statement that isn't writing and I wanted to see if there
> is a way to do error checking.
>
> Thanks
>
> Art
>
> student.write(reinterpret_cast<char *>(&studentInfo),sizeof(studentInfo));


What type is student?

  Réponse avec citation
Vieux 07/12/2007, 13h58   #4
Art Cummings
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: write

>>
>> student.write(reinterpret_cast<char
>> *>(&studentInfo),sizeof(studentInfo));

>
> What type is student?
>


student is an arrray of structures

Art


  Réponse avec citation
Vieux 07/12/2007, 14h40   #5
Kai-Uwe Bux
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: write

Art Cummings wrote:

>>>
>>> student.write(reinterpret_cast<char
>>> *>(&studentInfo),sizeof(studentInfo));

>>
>> What type is student?
>>

>
> student is an arrray of structures


You mean as in:

some_structure student [some_size];

In that case, the line should not compile. There would be no write() member
function.


Best

Kai-Uwe Bux
  Réponse avec citation
Vieux 07/12/2007, 16h02   #6
Art Cummings
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: write


>
> In that case, the line should not compile. There would be no write()
> member
> function.
>
>

Actually it does compile and it writes to disk. The members are populated
as I loop thru the array, and then I write the array of structures to disk.

Thanks
Art


  Réponse avec citation
Vieux 07/12/2007, 16h04   #7
James Kanze
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: write

On Dec 7, 10:46 am, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
> Art Cummings wrote:
> > does the write function have a return type?


> The write function from basic_ostream returns a basic_ostream&.


> > I've got a write statement
> > that isn't writing and I wanted to see if there is a way to do error
> > checking.


> The returned reference refers to the stream and you could check the flags.


> > student.write(reinterpret_cast<char *>(&studentInfo),sizeof(studentInfo));


> "student" is a rather peculiar name for a stream.


In addition to the other comments, I'd remind the OP that unless
studentInfo is an array of a character type (char or unsigned
char), ostream::write probably won't do anything useful with it.
(The reinterpret_cast makes me somewhat suspicious, but I've
formatted into arrays of unsigned char on occasion, and used
just such a reinterpret_cast to convert the unsigned char* to
char*. Except that when writing, I'd always cast to "char
const*".)

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
  Réponse avec citation
Vieux 07/12/2007, 16h35   #8
terminator
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: write

On Dec 7, 5:40 pm, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
> Art Cummings wrote:
>
> >>> student.write(reinterpret_cast<char
> >>> *>(&studentInfo),sizeof(studentInfo));

>
> >> What type is student?

>
> > student is an arrray of structures

>
> You mean as in:
>
> some_structure student [some_size];
>
> In that case, the line should not compile. There would be no write() member
> function.
>
> Best
>
> Kai-Uwe Bux


a stream can be thougt of as a sequence of records,but I think OP
should give more info.

regards,
FM.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h50.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17706 seconds with 16 queries