#include <sstream> char uncompressedData[DataSize]; // Suppose this contains your data std::istringstream iss(uncompressedData); iss >> myInt >> myDouble; // etc.
using file stream to open in memory buffer
Damn, thanks a ton aprosenf.. I''ve been checking out stuff on the iostream library for hours now trying to figure out how I would do that. That did come across my mind although I wasn''t sure if it would work. Thanks for confirming it. Does it matter if my buffer is of type BYTE though?
another question.. if i were to use the extraction operator on 2 seperate times would the data be taken from the beginning of the stream both times or would it be take from the correct position?
iss >> data1;
iss >> data2;
iss >> data1;
iss >> data2;
From the header file...
I think that should answer your question.
quote:
typedef struct unsigned char BYTE;
I think that should answer your question.
quote:Original post by DarkSaint
another question.. if i were to use the extraction operator on 2 seperate times would the data be taken from the beginning of the stream both times or would it be take from the correct position?
iss >> data1;
iss >> data2;
The extraction operators wouldn''t be very helpful if you had to manually advance the file pointer each time. Neither would any input/output functionality, for that matter.
well, that doesn''t really answer my question. It''s still unclear as to whether or not I could create a istringstream object passing an array of BYTE to it. I know BYTE is of type unsigned char but does istringstream work with unsigned char as well as char?
It works with unsigned char, but it's considered a separate type from char. This would indeed require some extra code to handle:
And you probably don't even need to specialize the basic_string, that's just me being anal retentive
[edited by - Zipster on June 4, 2004 12:33:58 AM]
basic_istringstream<BYTE> stringStream(basic_string<BYTE>(myByteBuffer));
And you probably don't even need to specialize the basic_string, that's just me being anal retentive
[edited by - Zipster on June 4, 2004 12:33:58 AM]
Doing extra code for a specialized istringstream of unsigned chars is not necessary. You can just cast your BYTE array to an a char * and everything will work. I tested doing a specialized istringstream and it didn't work too well. It gave compiler errors trying to read in a single char, either signed or unsigned, or an array of chars (i.e. a string), either signed or unsigned. Besides, if you look at the <istream> header, the unsigned versions of operator >> just calls the signed version with a cast, so there is no change in functionality.
std::istringstream iss((char *)myUnsignedData);
[edited by - aprosenf on June 5, 2004 10:51:21 AM]
std::istringstream iss((char *)myUnsignedData);
[edited by - aprosenf on June 5, 2004 10:51:21 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement