Print ( char )10?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey, I'm trying to write a file with unix-style newlines (ASCII character 10)
from a c++ program on Windows...it seems that the most straightforward way to
do that is just to print ( char )10, but it seems that when I try to print
that to the file, the program still prints the full CR+LF Windows-style
ending. The code I have looks something like this:

param_file<<"BSEARCH_ALG SIMPLE"<<( char )10;

Is there any way to keep the program (and/or Windows?) from converting my (
char )10 into a CR+LF?

I am writing output that will be input to a program that expects
unix-formatted files.

Cheers,
Joe
 
Hey, I'm trying to write a file with unix-style newlines (ASCII character 10)
from a c++ program on Windows...it seems that the most straightforward way to
do that is just to print ( char )10, but it seems that when I try to print
that to the file, the program still prints the full CR+LF Windows-style
ending. The code I have looks something like this:

param_file<<"BSEARCH_ALG SIMPLE"<<( char )10;

Is there any way to keep the program (and/or Windows?) from converting my (
char )10 into a CR+LF?

I am writing output that will be input to a program that expects
unix-formatted files.

You have to open the file in binary mode or call _setmode to suppress the
line terminator translation and Ctrl+Z processing.

P.S. I'd use '\n' instead of (char) 10.
 
Greetings,

Try using some old C code instead of C++ streams. Try using printf to write
strings of ascii characters to a text file opened using fopen. I don't think
printf does any background "helpful" conversions. Some folks complain that's
what makes old C difficult to use, but it is also what makes it powerful -
plain, simple, straight forward.

Mike
 
mike said:
Greetings,

Try using some old C code instead of C++ streams. Try using printf to write
strings of ascii characters to a text file opened using fopen. I don't think
printf does any background "helpful" conversions. Some folks complain that's
what makes old C difficult to use, but it is also what makes it powerful -
plain, simple, straight forward.

Streams opened in text mode in C (or C++) convert \n to the correct line
terminator for the host platform (CRLF for Windows). Open the file with
"b" in C and with std::binary in C++ to avoid this "background helpful
conversion".

Tom
 
Thanks, all...I figured out just after posting this that opening the file in
binary mode would do the trick.

Cheers,
Joe
 
Back
Top