473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Print ( char )10?

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

Nov 17 '05 #1
4 2268
On Mon, 19 Sep 2005 04:36:03 -0700, jceddy
<jc****@discussions.microsoft.com> wrote:
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.

--
Doug Harrison
VC++ MVP
Nov 17 '05 #2
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

"jceddy" wrote:
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

Nov 17 '05 #3
mike east wrote:
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
Nov 17 '05 #4
Thanks, all...I figured out just after posting this that opening the file in
binary mode would do the trick.

Cheers,
Joe

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tristan Miller | last post by:
Greetings. I have an XML file listing various information about text glyphs (Unicode value, HTML entity name, SGML entity name, etc.). All glyphs have a Unicode value, but not all of them have...
29
by: JS | last post by:
I would like to print char 'd': main(){ char g; g = 'a'; g = 'b'; g = 'c'; g = 'd';
2
by: chiara | last post by:
Hi! This is a piece of a code I wrote. It was perfectly working but now it is giving me some problems I can not understand. I scan a directory (ss_data) and I count its alaments. then I print...
1
by: Michael Beck | last post by:
I need to select one of about 15 printers, which I have been able to do. Then I need to set that printer as the printer to use, run a Crystal Reports reports, and track if/when the printing job...
3
by: QQ | last post by:
Hello, Here is my simple program int main() { unsigned char a =0x81; char b = 0x81; printf("unsigned char = 0x%x(%d), char = 0x%x(%d)\n",a,a,b,b); printf("cast char to unsigned...
2
by: tutufan | last post by:
Hi, I'm trying to use template metaprogramming to print (for debugging purposes) the contents of an arbitrary (random-access) container. So, for example, I'd like to be able to print a...
5
by: Shraddha | last post by:
Suppose we are having 3 variables...a,b,c And we want to print the permutations of these variables...Such as...abc,acb,bca...all 6 of them... But we are not supposed to do it mannually... I...
2
by: laurent.pauloin | last post by:
Hello I have a buffer of char and I want to print in a 64 bit word in hexa. charbuff0 charbuff1 charbuff2 charbuff3 charbuff4 charbuff5 charbuff6 charbuff7 64bit msb 64bit lsb
3
by: Tim | last post by:
Folks, I'm trying to format a print string so that it reports progress whilst processing a looping structure with a date time stamp appended to the end of the string. This started out life as a...
21
by: arnuld | last post by:
I have created a program to print the input words on stdout. Input is taken dynamically from stdin. In each word, each input character is allocated dynamically. I have ran this program with a file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.