Click here to Skip to main content
16,015,594 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: whats wrong with this? Pin
jan larsen4-Apr-02 23:33
jan larsen4-Apr-02 23:33 
GeneralRe: whats wrong with this? Pin
Mazdak5-Apr-02 0:28
Mazdak5-Apr-02 0:28 
GeneralRe: whats wrong with this? Pin
Christian Graus5-Apr-02 0:33
protectorChristian Graus5-Apr-02 0:33 
GeneralRe: whats wrong with this? Pin
jan larsen5-Apr-02 2:57
jan larsen5-Apr-02 2:57 
AnswerRe: whats wrong with this? Pin
alex.barylski4-Apr-02 23:34
alex.barylski4-Apr-02 23:34 
AnswerRe: whats wrong with this? Pin
Christian Graus4-Apr-02 23:46
protectorChristian Graus4-Apr-02 23:46 
GeneralRe: whats wrong with this? Pin
Mazdak4-Apr-02 23:55
Mazdak4-Apr-02 23:55 
GeneralRe: whats wrong with this? Pin
Christian Graus5-Apr-02 0:07
protectorChristian Graus5-Apr-02 0:07 
Every malloced pointer needs to be freed and every newed pointer needs to be deleted. You can't mix them up. new is better because it offers constructors and destructors, so there is good reason to just use new/delete, and thus never get them confused. The fact you're using AfxMessageBox & CString means you've got MFC available, yes ? So use the code I gave you to get the file length, and if you've got some reason to want to create a char* yourself of that size, use new to create it. There's no direct benefit in this case, but there's a benefit as I said in preferring the C++ to the C 'equivelant'. There's more to it, but I'd need to dig up my copy of 'Effective C++' to remind myself of it all.

If you're going to fill a char array with the contents of the file, why not read it into a std::string via an istringstream and an ifstream to read the file ? No messing around with pointers, memory is managed for you, and if you need a char * directly, use c_str() on the std::string to get it.



Christian

The tragedy of cyberspace - that so much can travel so far, and yet mean so little.

"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
GeneralRe: whats wrong with this? Pin
Mazdak5-Apr-02 0:19
Mazdak5-Apr-02 0:19 
GeneralRe: whats wrong with this? Pin
Christian Graus5-Apr-02 0:30
protectorChristian Graus5-Apr-02 0:30 
GeneralRe: whats wrong with this? Pin
Mazdak5-Apr-02 0:59
Mazdak5-Apr-02 0:59 
GeneralRe: whats wrong with this? Pin
Mazdak5-Apr-02 1:46
Mazdak5-Apr-02 1:46 
GeneralRe: whats wrong with this? Pin
Christian Graus5-Apr-02 9:57
protectorChristian Graus5-Apr-02 9:57 
AnswerRe: whats wrong with this? Pin
Jon Hulatt5-Apr-02 5:51
Jon Hulatt5-Apr-02 5:51 
GeneralRe: whats wrong with this? Pin
Mazdak5-Apr-02 6:11
Mazdak5-Apr-02 6:11 
GeneralNetmessagebuffersend(): this is strange! Pin
Jörg Anslik4-Apr-02 21:42
Jörg Anslik4-Apr-02 21:42 
GeneralDirectShow StillCap problem Pin
Ruzicka4-Apr-02 21:37
Ruzicka4-Apr-02 21:37 
Generalbasic_string Pin
Niklas L4-Apr-02 21:37
Niklas L4-Apr-02 21:37 
GeneralRe: basic_string Pin
Niklas L4-Apr-02 21:39
Niklas L4-Apr-02 21:39 
GeneralRe: basic_string Pin
Joaquín M López Muñoz4-Apr-02 22:32
Joaquín M López Muñoz4-Apr-02 22:32 
GeneralRe: basic_string Pin
Joao Vaz4-Apr-02 23:49
Joao Vaz4-Apr-02 23:49 
GeneralRe: basic_string Pin
Tim Smith5-Apr-02 3:48
Tim Smith5-Apr-02 3:48 
GeneralRe: basic_string Pin
Joao Vaz5-Apr-02 4:56
Joao Vaz5-Apr-02 4:56 
GeneralRe: basic_string Pin
Joaquín M López Muñoz5-Apr-02 5:40
Joaquín M López Muñoz5-Apr-02 5:40 
GeneralRe: basic_string Pin
Joao Vaz5-Apr-02 6:03
Joao Vaz5-Apr-02 6:03 

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.