473,320 Members | 1,988 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,320 software developers and data experts.

Binary outout to std::cout

What is the correct portable way of outputting binary data to cout? I
know that I can call _setmode(1, _O_BINARY) but that only works for
MSDOS.

And I *have* tried to Google it, but I have not been able to produce
any working code from what I found. Could anyone please extend the code
below, so that it writes binary data to cout without modifying it.
(<LF> is modified to <CR><LF> under MSDOS)?

#include <iostream>
void main()
{
std::cout.setf(std::ios_base::binary);
std::cout.write("\r\n", 2);
}

May 31 '06 #1
1 19274
mo*****@gmail.com wrote:
What is the correct portable way of outputting binary data to cout? I
know that I can call _setmode(1, _O_BINARY) but that only works for
MSDOS.

And I *have* tried to Google it, but I have not been able to produce
any working code from what I found. Could anyone please extend the code
below, so that it writes binary data to cout without modifying it.
(<LF> is modified to <CR><LF> under MSDOS)?

#include <iostream>
void main()
{
std::cout.setf(std::ios_base::binary);
std::cout.write("\r\n", 2);
}


See F.A.Q. [15.13] at the follow URL:
http://www.parashift.com/c++-faq-lit...html#faq-15.13

"This is implementation dependent. Check with your compiler's
documentation."

Sincerely,

Peter Jansson
http://www.p-jansson.com/
http://www.jansson.net/
May 31 '06 #2

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

Similar topics

2
by: Pmb | last post by:
I've noticed a lot of people preferring std::cout over cout. May I ask why you prefer one over the other? thanks Pmb
6
by: clilley | last post by:
The following code causes a segmentation fault on DEC Tru64: foo.cc (built into libFoo.so) //--------------------------- include <iostream> bool createFoo() { std::cout << "createFoo" <<...
6
by: nish.parikh | last post by:
Hi, I am using std::cout to print a char pointer that is NULL. Subsequent calls to std::cout dont print anything. Is this the expected behavior? example: #include <iostream> int main( int...
19
by: Dancefire | last post by:
Hi, everyone It might be a simple question, but I really don't know the answer. char c = '1'; cout << c; The above code will only output a '1' rather than 0x31; If I use int cast, it can...
6
by: Roger | last post by:
Hello, I'm pretty new to C++ programming, and I'm teaching myself the language using various sources. This sounds stupid, but I am really confused on this... I was wondering why we have to write...
5
by: wongjoekmeu | last post by:
Dear All, I have written a small program to read in from console a user string. I wanted to be able to read in a string containing of all sorts of characters untill the user press enter. I have to...
11
by: Adrian | last post by:
Is it possible to save a copy of cout the same way you can save a copy of stdout in C (I know C version is portable, but unix portable is good enough for me). I have to use a library which...
58
by: Mark Casternoff | last post by:
I'm getting back into C++ after a long hiatus (they didn't have namespaces back then). I know this question is completely subjective, but I'd be interested in hearing which is the "better"...
2
by: donthomasino | last post by:
i get error c2886( when i use using std::cout; using std::string;) and when i change to (using namespace std; using namespace std;) i got error c2059 #include <iostream> #include <string>...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.