By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,505 Members | 1,165 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,505 IT Pros & Developers. It's quick & easy.

storin a istream in a char*

P: n/a
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

Sep 4 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
mw****@freenet.de wrote:
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
Sep 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.