Search code examples
c++csteganography

error in C++, what to do ?: could not find an match for ostream::write(long *, unsigned int)


I am trying to write data stored in a binary file using turbo C++. But it shows me an error

could not find an match for ostream::write(long *, unsigned int)

I want to write a 4 byte long data into that file. When i tries to write data using char pointer. It runs successfully. But i want to store large value i.e. eg. 2454545454 Which can be stored in long only.

I dont know how to convert 1 byte into bit. I have 1 byte of data as a character. Moreover what i m trying to do is to convert 4 chars into long and store data into it. And at the other side i want to reverse this so as to retrieve how many bytes of data i have written.

long *lmem;
lmem=new long;
*lmem=Tsize;
fo.write(lmem,sizeof(long));// error occurs here
delete lmem;

I am implementing steganography and i have successfully stored txt file into image but trying to retrieve that file data now.

EDIT:

I am using Turbo Complier.


Solution

  • Cast it to a char*

    long *lmem;
    lmem=new long;
    *lmem=Tsize;
    fo.write(reinterpret_cast<char*>(lmem),sizeof(long));
    delete lmem;
    

    Or even better (as allocation on the stack is far faster and less error prone)

    long lmem = Tsize;
    fo.write(reinterpret_cast<char*>(&lmem),sizeof(long));
    

    If Tsize is addressable and a long you could do this:

    fo.write(reinterpret_cast<char*>(&Tsize),sizeof(long));