Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > retrieving openmode from a stream

Reply
Thread Tools

retrieving openmode from a stream

 
 
Noah Roberts
Guest
Posts: n/a
 
      11-08-2006
I am writing a class that uses a passed in stream. The writing this
class performs is binary and so I would like to assert that the stream
is a binary stream. Problem is that I can't find any function to
retrieve that information from the stream. Looked in Josuttis, std,
msdn, and google but can't seem to find it. Never wanted to do this
before. Anyone know if and where such functionality resides?

 
Reply With Quote
 
 
 
 
Steve Pope
Guest
Posts: n/a
 
      11-09-2006
Noah Roberts <(E-Mail Removed)> wrote:

>I am writing a class that uses a passed in stream. The writing this
>class performs is binary and so I would like to assert that the stream
>is a binary stream. Problem is that I can't find any function to
>retrieve that information from the stream. Looked in Josuttis, std,
>msdn, and google but can't seem to find it. Never wanted to do this
>before. Anyone know if and where such functionality resides?


I'm guessing this functionality isn't there. Unix does not
distinguish between binary files and other types of files,
and C++ I/O was written with Unix in mind.

Another way of saying this is that the stream is always binary,
unless you have some OS-specific (and non-portable) function
that can tell you otherwise.

(Somebody correct me if I'm guessing wrong.)

Steve
 
Reply With Quote
 
 
 
 
tryptik@gmail.com
Guest
Posts: n/a
 
      11-09-2006
> Another way of saying this is that the stream is always binary,
> unless you have some OS-specific (and non-portable) function
> that can tell you otherwise.


My understanding and experience seem to indicate that the stream is
never truly binary - by nature, the stream is imposing formatting
information on the the underlying rdbuf. I say this because I have
been using the stream in binary mode and still having to deal with
strange formatting characters getting in there. (To be fair, I believe
I was picking up '\r' characters being inserted by the MS
implimentation of the stream where none exist in UNIX - there is
perhaps a flag to set this, but I never found it.)

To garauntee binary operations in the stream, you can use the get(),
read() and write() methods (and their associated methods - readsome(),
etc), or access the underlying streambuf directly, which is what I have
been doing. If you use the << or >>, you are not accessing the stream
in a binary fashion regardless of openmode.

-J

 
Reply With Quote
 
Richard Herring
Guest
Posts: n/a
 
      11-10-2006
In message <eivpj7$d4l$(E-Mail Removed)>, Steve Pope
<(E-Mail Removed)> writes
>Noah Roberts <(E-Mail Removed)> wrote:
>
>>I am writing a class that uses a passed in stream. The writing this
>>class performs is binary and so I would like to assert that the stream
>>is a binary stream. Problem is that I can't find any function to
>>retrieve that information from the stream. Looked in Josuttis, std,
>>msdn, and google but can't seem to find it. Never wanted to do this
>>before. Anyone know if and where such functionality resides?

>
>I'm guessing this functionality isn't there. Unix does not
>distinguish between binary files and other types of files,
>and C++ I/O was written with Unix in mind.


That may have been true for C, but you can't really say that of C++ -
ios_base::binary is part of the standard, so someone somewhere must have
thought it served some purpose.
>
>Another way of saying this is that the stream is always binary,
>unless you have some OS-specific (and non-portable) function
>that can tell you otherwise.
>
>(Somebody correct me if I'm guessing wrong.)
>

Well, an fstream itself "knows" whether ios_base::binary flag was passed
to open(), so if my interpretation of the OP's question as "how can I
find out if the stream was opened with the binary flag?" is correct,
this could (in principle) be achieved by the function
fstream::get_openmode().

Unfortunately it doesn't exist

--
Richard Herring
 
Reply With Quote
 
BobR
Guest
Posts: n/a
 
      11-10-2006

Steve Pope wrote in message ...
>Noah Roberts <(E-Mail Removed)> wrote:
>
>>I am writing a class that uses a passed in stream. The writing this
>>class performs is binary and so I would like to assert that the stream
>>is a binary stream. Problem is that I can't find any function to
>>retrieve that information from the stream. Looked in Josuttis, std,
>>msdn, and google but can't seem to find it. Never wanted to do this
>>before. Anyone know if and where such functionality resides?

>
>I'm guessing this functionality isn't there. Unix does not
>distinguish between binary files and other types of files,
>and C++ I/O was written with Unix in mind.
>
>Another way of saying this is that the stream is always binary,
>unless you have some OS-specific (and non-portable) function
>that can tell you otherwise.
>
>(Somebody correct me if I'm guessing wrong.)
>Steve


I found this in the MinGW(GCC) header, maybe it could explain (I did'nt check
it out).

/* --- from ..../bits/ios_base.h ---
/// Perform input and output in binary mode (as opposed to text mode).
/// This is probably not what you think it is; see
/// http://gcc.gnu.org/onlinedocs/libstd...o/howto.html#3 and
/// http://gcc.gnu.org/onlinedocs/libstd...o/howto.html#7 for more.
static const openmode binary = openmode(__ios_flags::_S_bin);

--- other headers ---
struct __ios_flags{
static const __int_type _S_bin = 0x04;
};
*/

--
Bob R
POVrookie


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
get stream mode flags from an opened stream Alexander Korsunsky C++ 1 02-17-2007 10:38 AM
How to GET multi-word input from a *file* stream as opposed to a *console* stream? sherifffruitfly@gmail.com C++ 9 04-27-2006 04:14 PM
File's Openmode and the Cursor position Al-Burak C++ 3 12-28-2005 12:25 PM
Doing readline in a thread from a popen4('rsync ...') stream blocks when the stream ends. Rasmusson, Lars Python 1 04-30-2004 08:10 AM
ios::openmode Marc Schellens C++ 1 07-16-2003 03:53 PM



Advertisments