468,458 Members | 1,848 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,458 developers. It's quick & easy.

storin a istream in a char*

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
1 1925
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.

Similar topics

3 posts views Thread by lpe540 | last post: by
6 posts views Thread by Jason K | last post: by
13 posts views Thread by Gianni Mariani | last post: by
7 posts views Thread by John Salmon | last post: by
4 posts views Thread by Jim Michaels | last post: by
4 posts views Thread by =?Utf-8?B?Sm9obg==?= | last post: by
4 posts views Thread by james.lawton | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.