Hi,
i had this problem before (posted here and solved it then) now i have
the same problem but more complicated and general...
basically i want to store the adress of a istream in a char* among
other pieces of information information and retrieve it later... like
this:
***********************
//supossing i have a istream
istream in("test.txt");
//i store its adress as a char
char* add=(char*)∈
//[....]
//inside the code of another function i create a pointer
istream * t;
//and restore its adress back
t=(ifstream*)add;
*******************
now thats works ok...
what i want now is to store not only the adress but also some text...
and the whole should look like a filename
lets say the adress is 0xDEAD i would like the char* to look like this
"file:DEADtext2.txt"
the prefix has a fixed length as well as the suffix....
i thought the adress would be 32 bit (4 bytes 32bit pentium machine)
so i wanted to store first in some strings like this(sorry for the ugly
code but im desperate :) ):
********
//store prefix
string pref="http:":
//store adress
string add=(char*)&in:
//store suffix
string suf="text2.txt":
//concatenate all three
string total = pref + add + suf;
char* add= total.cstr();
*******
cout<< sizeof(&in)<<endl;
says the size of the istream is 4 bytes...
but when i display add.length() it says its only three bytes long... so
im quite confused... so where is the last byte?
also when i display the elements of the istream:
cout<<(int)((char*)&in)[0]<<endl;
cout<<(int)((char*)&in)[1]<<endl;
cout<<(int)((char*)&in)[2]<<endl;
cout<<(int)((char*)&in)[3]<<endl;
then element 3 is a zero... thus there are only three bytes...
so two pleas for help:
how long is the adress actually?
how can i concatenate those three pieces of information and retrieve
them later too??
thanks in advance to all ideas, hints where to further look for and
answers...