storin a istream in a char*

M

mwebel

Hi,
My Module (B) needs to read from a istream (provided by another module
A) and again the module (C) i use accepts only char*.
So actually it accepts filenames. But i dont want to store the stream
onto the disk and pass it again. I am also not allowed to change the
API on the module i use. I can chang the way it works though.
So i thought i'd cheat by storing the stream adress in the char and
restoring it again once "inside" the code.


so my basic question is: Would this work?
heres the code id use:

//supossing i get a istream
istream in("test.txt");

//i store its adress as a char
char* d=(char*)∈

//inside the code i create a pointer
istream * t;

//and restore its adress back
t=(ifstream*)d;




using the code above with fstreams i achieve to read a file.
the thing is, that after my module is done the module A deletes and
deallocates the stream.
AFAIK there should not be a problem with this. because all i do is only
read operations.
can anyone reassure me on this?
thx in advance
 
D

Daniel Kay

Hi,
My Module (B) needs to read from a istream (provided by another module
A) and again the module (C) i use accepts only char*.
So actually it accepts filenames. But i dont want to store the stream
onto the disk and pass it again. I am also not allowed to change the
API on the module i use. I can chang the way it works though.
So i thought i'd cheat by storing the stream adress in the char and
restoring it again once "inside" the code.


so my basic question is: Would this work?
heres the code id use:

//supossing i get a istream
istream in("test.txt");

//i store its adress as a char
char* d=(char*)∈

//inside the code i create a pointer
istream * t;

//and restore its adress back
t=(ifstream*)d;




using the code above with fstreams i achieve to read a file.
the thing is, that after my module is done the module A deletes and
deallocates the stream.
AFAIK there should not be a problem with this. because all i do is only
read operations.
can anyone reassure me on this?

Hello!

Should work, but it very ugly code.

Cya,
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top