Discussion:
How can I "reopen" std::cin and std::cout in binary mode?
(too old to reply)
news.swva.net
2005-05-07 09:07:54 UTC
Permalink
How can I "reopen" std::cin and std::cout in binary mode on unix using GCC?
If you know how to do that with MS VC++ it would be even awesome!!!
thanks,
Ivan
Bill Marcum
2005-05-08 05:54:09 UTC
Permalink
On Sat, 07 May 2005 05:07:54 -0400, news.swva.net
Post by news.swva.net
How can I "reopen" std::cin and std::cout in binary mode on unix using GCC?
If you know how to do that with MS VC++ it would be even awesome!!!
thanks,
Ivan
In unix there is no difference beween text and binary mode (unless that
is something specific to C++).
--
Test-tube babies shouldn't throw stones.
p***@treefic.com
2005-05-08 16:21:41 UTC
Permalink
Post by news.swva.net
How can I "reopen" std::cin and std::cout in binary mode on unix using GCC?
I think the answer is "you can't", since there is no way to make a c++
stream from a file descriptor. I only vaguely recall the details; I
think that perhaps one of the library implementations that I looked at
had a way to do it but it wasn't in the standard, or something. (I
think I was trying to make a c++ stream connected to a socket.) Perhaps
someone else will know the details.

Luckily you can substitute a "no-op", since there is no difference on
Unix.
Post by news.swva.net
If you know how to do that with MS VC++ it would be even awesome!!!
Try another group.


--Phil.
Roger Leigh
2005-05-08 18:19:38 UTC
Permalink
Post by news.swva.net
Post by news.swva.net
How can I "reopen" std::cin and std::cout in binary mode on unix
using GCC?
I think the answer is "you can't", since there is no way to make a c++
stream from a file descriptor. I only vaguely recall the details; I
think that perhaps one of the library implementations that I looked at
had a way to do it but it wasn't in the standard, or something.
You can create a stream buffer from an fd or FILE*; perhaps that's
what you are thinking of?

#include <cstdio>
#include <fstream>
#include <ext/stdio_filebuf.h>

int main(void)
{
// stream using a UNIX file descriptor
std::ofstream os;
__gnu_cxx::stdio_filebuf<char> fdbuf(1, std::ios::out);
os.std::ios::rdbuf(&fdbuf);

os << "Hello, world!" << std::endl;

// stream using an ISO C FILE structure
__gnu_cxx::stdio_filebuf<char> filbuf(stdout, std::ios::out);
os.std::ios::rdbuf(&filbuf);
os << "Goodbye!" << std::endl;

return 0;
}

Using the same method, you can set the stream buffer for any stream,
including std::cin and std::cout.


Regards,
Roger

- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
Jhair Tocancipa Triana
2005-05-12 11:19:35 UTC
Permalink
Post by p***@treefic.com
Post by news.swva.net
How can I "reopen" std::cin and std::cout in binary mode on unix using GCC?
I think the answer is "you can't", since there is no way to make a c++
stream from a file descriptor. I only vaguely recall the details; I
think that perhaps one of the library implementations that I looked at
had a way to do it but it wasn't in the standard, or something. (I
think I was trying to make a c++ stream connected to a socket.) Perhaps
someone else will know the details.
You can find some details here:

http://www.ginac.de/~kreckel/fileno/
--
--Jhair

PGP key available from public servers - ID: 0xBAA600D0
Ralf Fassel
2005-05-12 15:27:55 UTC
Permalink
* "news.swva.net" <***@example.net>
| How can I "reopen" std::cin and std::cout in binary mode on unix using GCC?
| If you know how to do that with MS VC++ it would be even awesome!!!

With VC++, you could try to link against binmode.obj (included with
the compiler), which switches the regular streams to binary mode.

Don't know whether the C++ streams are affected by this, and whether
binmode.obj can be used with gcc on windows.

R'

Loading...