Connecting Tech Pros Worldwide Help | Site Map

storin a istream in a char*

 
LinkBack Thread Tools Search this Thread
  #1  
Old September 4th, 2006, 07:55 PM
mwebel@freenet.de
Guest
 
Posts: n/a
Default 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


  #2  
Old September 4th, 2006, 08:25 PM
Daniel Kay
Guest
 
Posts: n/a
Default Re: storin a istream in a char*

mwebel@freenet.de wrote:
Quote:
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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.