Click here to Skip to main content
15,881,882 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: C fread to read 512k binary file Pin
David Crow10-Aug-16 16:45
David Crow10-Aug-16 16:45 
AnswerRe: C fread to read 512k binary file Pin
k505411-Aug-16 12:46
mvek505411-Aug-16 12:46 
GeneralRe: C fread to read 512k binary file Pin
David Crow11-Aug-16 16:24
David Crow11-Aug-16 16:24 
AnswerRe: C fread to read 512k binary file Pin
Daniel Pfeffer10-Aug-16 21:15
professionalDaniel Pfeffer10-Aug-16 21:15 
GeneralRe: C fread to read 512k binary file Pin
Fossi Bluman11-Aug-16 1:58
Fossi Bluman11-Aug-16 1:58 
GeneralRe: C fread to read 512k binary file Pin
Daniel Pfeffer11-Aug-16 3:54
professionalDaniel Pfeffer11-Aug-16 3:54 
GeneralRe: C fread to read 512k binary file Pin
Fossi Bluman11-Aug-16 6:56
Fossi Bluman11-Aug-16 6:56 
AnswerRe: C fread to read 512k binary file Pin
Software_Developer20-Aug-16 0:03
Software_Developer20-Aug-16 0:03 
Hello.
Here is another solution.

C#
//******************************************
// reading an entire binary file the c++ way

#include <iostream>
#include <fstream>
using namespace std;

int main (){

  streampos size;
  char * memblock;
  cout<<" \n\n";

  // open file as binary
  ifstream file ("myfile.bin", ios::in|ios::binary|ios::ate);
  if ( file.is_open() ){

    // get file size
    size = file.tellg();

    // alloocate appropiate file size + 1 for '\0'
    memblock = new char [size+1];

    // go to begining of file
    file.seekg (0, ios::beg);

    // read entire file into ram memory
    file.read (memblock, size);
    file.close();

    // display size of file
    cout << "the entire file content of "<< size <<" bytes is in memory  \n\n\n";
 
    // release memory
    delete[] memblock;
  }
  else cout << "Unable to open file\n\n";

    
cout<<"Press ANY key to close.\n\n";
cin.ignore(); cin.get();
return 0;
}                         


modified 21-Aug-16 0:39am.

GeneralRe: C fread to read 512k binary file Pin
Fossi Bluman23-Aug-16 6:45
Fossi Bluman23-Aug-16 6:45 
QuestionVector as function return Pin
Donguy19769-Aug-16 15:40
Donguy19769-Aug-16 15:40 
AnswerRe: Vector as function return Pin
Richard MacCutchan9-Aug-16 20:57
mveRichard MacCutchan9-Aug-16 20:57 
QuestionAdding Text to the Frame Of a Dialog Pin
ForNow9-Aug-16 4:39
ForNow9-Aug-16 4:39 
AnswerRe: Adding Text to the Frame Of a Dialog Pin
jeron19-Aug-16 8:33
jeron19-Aug-16 8:33 
GeneralRe: Adding Text to the Frame Of a Dialog Pin
ForNow9-Aug-16 13:07
ForNow9-Aug-16 13:07 
AnswerRe: Adding Text to the Frame Of a Dialog Pin
leon de boer9-Aug-16 19:05
leon de boer9-Aug-16 19:05 
GeneralRe: Adding Text to the Frame Of a Dialog Pin
ForNow10-Aug-16 3:47
ForNow10-Aug-16 3:47 
SuggestionRe: Adding Text to the Frame Of a Dialog Pin
David Crow10-Aug-16 5:41
David Crow10-Aug-16 5:41 
GeneralRe: Adding Text to the Frame Of a Dialog Pin
leon de boer10-Aug-16 17:07
leon de boer10-Aug-16 17:07 
GeneralRe: Adding Text to the Frame Of a Dialog Pin
ForNow10-Aug-16 20:31
ForNow10-Aug-16 20:31 
GeneralRe: Adding Text to the Frame Of a Dialog Pin
leon de boer11-Aug-16 3:00
leon de boer11-Aug-16 3:00 
GeneralRe: Adding Text to the Frame Of a Dialog Pin
ForNow11-Aug-16 3:18
ForNow11-Aug-16 3:18 
GeneralRe: Adding Text to the Frame Of a Dialog Pin
ForNow11-Aug-16 2:58
ForNow11-Aug-16 2:58 
AnswerRe: Adding Text to the Frame Of a Dialog Pin
Richard MacCutchan9-Aug-16 20:49
mveRichard MacCutchan9-Aug-16 20:49 
Questionconst "getter" but updating on request? Pin
FriendOfAsherah8-Aug-16 21:20
FriendOfAsherah8-Aug-16 21:20 
AnswerRe: const "getter" but updating on request? Pin
Jochen Arndt8-Aug-16 23:46
professionalJochen Arndt8-Aug-16 23:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.