How to import a binary file - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to import a binary file

MidasTheDudeMidasTheDude Posts: 2Member
Hi All,

I am working on a project where i need to import a binary file into a RichEdit. I searched all over and i could not find any help about this.

When i import the binary file, the most bytes are gone, it shows only the bytes that appeared to be ANSI code. so byte 0-32 are erased by RichEdit(i think)

I tried to put plaintext on, but that wont fix the problem.

Is there any way to import a complete binary file into RichEdit. It would be nice if the characters where shown as hex in stead of text.

The code i am using:
RichEdit1->Lines->LoadFromFile(OpenDialog1->FileName);

Kind Regards,

Midas


Comments

  • MidasTheDudeMidasTheDude Posts: 2Member
    here is the answer to my own question.just in case someone is looking for it:

    #include
    #include

    int main () {
    char * buffer;
    long size;
    ifstream file ("example.dat", ios::in|ios::binary|ios::ate);
    size = file.tellg();
    file.seekg (0, ios::beg);
    buffer = new char [size];
    file.read (buffer, size);
    file.close();

    cout << "the complete file is in a buffer";

    delete[] buffer;
    return 0;
    }

    Cheers!

    midas
Sign In or Register to comment.