C++ Builder

Moderators: Lundin
Number of threads: 518
Number of posts: 1158

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How to import a binary file Posted by MidasTheDude on 30 Apr 2011 at 10:56 PM
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


Report
Re: How to import a binary file Posted by MidasTheDude on 7 May 2011 at 12:59 PM
here is the answer to my own question.just in case someone is looking for it:

#include <iostream.h>
#include <fstream.h>

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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.