Click here to Skip to main content
15,892,674 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: using STL Vector Pin
Stephen Hewitt11-Apr-07 16:01
Stephen Hewitt11-Apr-07 16:01 
QuestionNo Windows XP Style controls !!! Why ? Pin
Avinash Gupta ITER11-Apr-07 8:41
Avinash Gupta ITER11-Apr-07 8:41 
AnswerRe: No Windows XP Style controls !!! Why ? Pin
Dustin Henry11-Apr-07 9:03
Dustin Henry11-Apr-07 9:03 
GeneralRe: No Windows XP Style controls !!! Why ? Pin
sthotakura11-Apr-07 10:41
sthotakura11-Apr-07 10:41 
GeneralThanks !!! Pin
Avinash Gupta ITER12-Apr-07 21:37
Avinash Gupta ITER12-Apr-07 21:37 
Questionsaving and printing Pin
cyn811-Apr-07 8:09
cyn811-Apr-07 8:09 
Questionconverting int to char Pin
cyn811-Apr-07 8:00
cyn811-Apr-07 8:00 
AnswerRe: converting int to char Pin
doctorpi11-Apr-07 8:39
doctorpi11-Apr-07 8:39 
I hope this help


Streams were originally designed for text, so the default output mode is text. In text mode, the newline character (hexadecimal 10) expands to a carriage return–linefeed (16-bit only). The expansion can cause problems, as shown here:

#include <fstream.h>
int iarray[2] = { 99, 10 };
void main()
{
ofstream os( "test.dat" );
os.write( (char *) iarray, sizeof( iarray ) );
}

You might expect this program to output the byte sequence { 99, 0, 10, 0 }; instead, it outputs { 99, 0, 13, 10, 0 }, which causes problems for a program expecting binary input. If you need true binary output, in which characters are written untranslated, you have several choices:

Construct a stream as usual, then use the setmode member function, which changes the mode after the file is opened:
ofstream ofs ( "test.dat" );
ofs.setmode( filebuf::binary );
ofs.write( char*iarray, 4 ); // Exactly 4 bytes written

Specify binary output by using the ofstream constuctor mode argument:
#include <fstream.h>
#include <fcntl.h>
#include <io.h>
int iarray[2] = { 99, 10 };
void main()
{
ofstream os( "test.dat", ios::binary );
ofs.write( iarray, 4 ); // Exactly 4 bytes written
}

Use the binary manipulator instead of the setmode member function:
ofs << binary;

Use the text manipulator to switch the stream to text translation mode.

Open the file using the run-time _open function with a binary mode flag:
filedesc fd = _open( "test.dat",
_O_BINARY | _O_CREAT | _O_WRONLY );
ofstream ofs( fd );
ofs.write( ( char* ) iarray, 4 ); // Exactly 4 bytes written
AnswerRe: converting int to char Pin
cp987611-Apr-07 13:46
cp987611-Apr-07 13:46 
QuestionAssigning parent to a Dialog Pin
doctorpi11-Apr-07 7:03
doctorpi11-Apr-07 7:03 
AnswerRe: Assigning parent to a Dialog Pin
led mike11-Apr-07 7:10
led mike11-Apr-07 7:10 
GeneralRe: Assigning parent to a Dialog Pin
doctorpi11-Apr-07 7:41
doctorpi11-Apr-07 7:41 
GeneralRe: Assigning parent to a Dialog [modified] Pin
doctorpi11-Apr-07 8:25
doctorpi11-Apr-07 8:25 
GeneralRe: Assigning parent to a Dialog Pin
led mike11-Apr-07 8:56
led mike11-Apr-07 8:56 
QuestionWriting XML to file Pin
LCI11-Apr-07 6:22
LCI11-Apr-07 6:22 
AnswerRe: Writing XML to file Pin
led mike11-Apr-07 6:55
led mike11-Apr-07 6:55 
QuestionCompiler Switches /MD and MT Pin
nde_plume11-Apr-07 6:10
nde_plume11-Apr-07 6:10 
AnswerRe: Compiler Switches /MD and MT [modified] Pin
sthotakura11-Apr-07 11:35
sthotakura11-Apr-07 11:35 
QuestionWin32 Graphical drawing. Pin
deville7511-Apr-07 4:33
deville7511-Apr-07 4:33 
AnswerRe: Win32 Graphical drawing. Pin
Cedric Moonen11-Apr-07 4:45
Cedric Moonen11-Apr-07 4:45 
GeneralRe: Win32 Graphical drawing. Pin
deville7511-Apr-07 4:53
deville7511-Apr-07 4:53 
GeneralRe: Win32 Graphical drawing. Pin
deville7511-Apr-07 5:20
deville7511-Apr-07 5:20 
GeneralRe: Win32 Graphical drawing. Pin
deville7511-Apr-07 5:25
deville7511-Apr-07 5:25 
GeneralRe: Win32 Graphical drawing. Pin
Cedric Moonen11-Apr-07 7:31
Cedric Moonen11-Apr-07 7:31 
Questionhow to convert _variant_t to char*? Pin
Arris7411-Apr-07 4:06
Arris7411-Apr-07 4:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.