 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Axel Panning Guest
|
Posted: Thu Apr 21, 2005 8:48 am Post subject: frage zu ofstream::write() |
|
|
Hallo,
habe folgenden Code. Will ein paar Daten in Binärform speichern. Ich
wollte mir einfach alle Daten als "char*" casten und dann halt ab in die
Datei.
--------->snip
std::ofstream s(filename);
unsigned char fileFormat = 0;
char* charSize = (char*) &mySize; //mySize ist ein Int
char* charData = (char*) daten; //daten ist ein *double
unsigned char* ff = (unsigned char*) &fileFormat;
s.write(fileFormat , 1); //ERROR
s.write(&fileFormat , 1); //ERROR
s.write(charSize , sizeof(int)); //-> ok
s.write(charData , mySize* sizeof(double) ); //-> ok
snap<---------
bei den markierten zeilen erhalte ich immer folgenden Fehler:
error C2664: 'write' : Konvertierung des Parameters 1 von 'const
unsigned char *' in
'const char *' nicht moeglich
Gleiches Problem taucht auf, wenn ich anstatt "unsigned" "signed"
verwenden möchte. Soweit ich weiß, gibt es für write() aber 3
Implementierungen:
write(const char*, length)
write(const signed char*, length)
write(const unsigned char*, length)
Warum will der immer in char* wandeln?
Danke & Gruß Axel
p.s.: nutze den MS-Compiler von MS-VS6 (sp5)
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Thomas Maeder Guest
|
Posted: Thu Apr 21, 2005 5:14 pm Post subject: Re: frage zu ofstream::write() |
|
|
Axel Panning <axel (AT) harnackstrasse (DOT) de> writes:
| Quote: | --------->snip
std::ofstream s(filename);
unsigned char fileFormat = 0;
char* charSize = (char*) &mySize; //mySize ist ein Int
char* charData = (char*) daten; //daten ist ein *double
unsigned char* ff = (unsigned char*) &fileFormat;
s.write(fileFormat , 1); //ERROR
s.write(&fileFormat , 1); //ERROR
s.write(charSize , sizeof(int)); //-> ok
s.write(charData , mySize* sizeof(double) ); //-> ok
snap<---------
bei den markierten zeilen erhalte ich immer folgenden Fehler:
error C2664: 'write' : Konvertierung des Parameters 1 von 'const
unsigned char *' in
'const char *' nicht moeglich
Gleiches Problem taucht auf, wenn ich anstatt "unsigned" "signed"
verwenden möchte. Soweit ich weiß, gibt es für write() aber 3
Implementierungen:
write(const char*, length)
write(const signed char*, length)
write(const unsigned char*, length)
|
Ich kenne nur
write(const char*, length)
Wo hast Du die anderen gefunden?
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Axel Panning Guest
|
Posted: Fri Apr 22, 2005 9:56 am Post subject: Re: frage zu ofstream::write() |
|
|
| Quote: |
Ich kenne nur
write(const char*, length)
Wo hast Du die anderen gefunden?
|
Aus MSDN-Doku, die man zu MSVC6 dazu bekommt: "Visual C++ Dokumentation"
-> "Reference" -> "C/C++ Language and C++ Libraries" -> "iostream
Library Reference" -> "ostream" -> "Member Functions" -> "ostream::write"
snip ---->
ostream::write
ostream& write( const char* pch, int nCount );
ostream& write( const unsigned char* puch, int nCount );
ostream& write( const signed char* psch, int nCount );
Parameters
pch, puch, psch
A pointer to a character array.
nCount
The number of characters to be written.
Remarks
Inserts a specified number of bytes from a buffer into the stream. If
the underlying file was opened in text mode, additional carriage return
characters may be inserted. The write function is useful for binary
stream output.
<----snap
unter "oftream" steht es sei ein derivat von "ostream"
Auf "http://www.cplusplus.com/ref/iostream/ostream/write.html" sehe ich
allerdings, daß es das dort nicht gibt. Scheint wohl ein Fehler inder
MS-Doku zu sein :/. Hätte ich auch eher drauf kommen können.
Sorry & Danke
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
|
|
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
|
|