STL: how to use a char array as an input stream
My application receives BINARY word-aligned data via character arrays. In other words, the sending application has a struct containing floats, ints, chars, etc. and what the application does is basically memcpy the struct into a char buffer and sends that buffer to my application.
My application recieves (a copy of) the buffer in a message, drops the buffer to a file, and then uses ifstream to open the file as a stream and reads data from it.
My question is can I cut out the "dropping the buffer to a file" part and read data directly from the allocated char buffer as if it was a stream? If so, how do I set up the char buffer as an input stream?
Thank you for your advice.
Re: STL: how to use a char array as an input stream
Is this what you want to do?
Code:
typedef struct
{
long a;
double b;
float c;
char buf[126];
} DATA;
int main(int argc, char* argv[])
{
char iobuf[sizeof(DATA)];
// get iobuf from the stream
DATA* pData = reinterpret_cast<DATA*>(iobuf);
// now use pData
return 0;
}