Home > Archive > VC STL > March 2005 > strstream doesn't seem to support iostream interfaces?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
strstream doesn't seem to support iostream interfaces?
|
|
| mc@pochta.ws 2005-03-20, 4:03 pm |
| Hello,
I'm trying to use "iostream" as an input parameter, allowing thereby a
user to specify, for example a file stream ("fstream") or memory stream
("strstream"). With "fstream" all seems to work fine, while "strstream"
isn't that case. I've managed to get a sample code describing the
problem I'm experiencing (Visual Studio 2003, empty console
application). Any ideas appreciated!
#include <iostream>
#include <fstream>
#include <strstream>
using namespace std;
void Test(iostream* DataStream)
{
int i = 6347;
DataStream->s p(0);
DataStream->write((const char*)&i, 4);
int j = 0;
DataStream->s p(0);
DataStream->read((char*)&j, 4);
}
int main(int argc, char* argv[])
{
strstream sx;
//Test(&sx); // j == 0 (why???)
int i = 6347;
((iostream*)&sx)->s p(0);
((iostream*)&sx)->write((const char*)&i, 4);
int j = 0;
((iostream*)&sx)->s p(0);
((iostream*)&sx)->read((char*)&j, 4);
fstream fx;
fx.open("temp", ios_base::in | ios_base::out | ios_base::binary |
ios_base::trunc);
Test(&fx); // j == 6347
}
| |
|
|
|
|
|
|
|