Click here to Skip to main content
15,888,351 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: DllMain and its usage (Followup to a post by Jeremy Falcon) Pin
PJ Arends31-Aug-06 9:19
professionalPJ Arends31-Aug-06 9:19 
GeneralRe: DllMain and its usage (Followup to a post by Jeremy Falcon) Pin
PJ Arends31-Aug-06 9:33
professionalPJ Arends31-Aug-06 9:33 
GeneralRe: DllMain and its usage (Followup to a post by Jeremy Falcon) Pin
Michael Dunn31-Aug-06 18:42
sitebuilderMichael Dunn31-Aug-06 18:42 
GeneralRe: DllMain and its usage (Followup to a post by Jeremy Falcon) Pin
PJ Arends31-Aug-06 21:14
professionalPJ Arends31-Aug-06 21:14 
QuestionHeap corruption?! Pin
Nader Elshehabi31-Aug-06 7:55
Nader Elshehabi31-Aug-06 7:55 
AnswerRe: Heap corruption?! Pin
Zac Howland31-Aug-06 8:15
Zac Howland31-Aug-06 8:15 
QuestionRe: Heap corruption?! Pin
Nader Elshehabi31-Aug-06 9:01
Nader Elshehabi31-Aug-06 9:01 
AnswerRe: Heap corruption?! Pin
Zac Howland31-Aug-06 9:08
Zac Howland31-Aug-06 9:08 
Nader Elshehabi wrote:
Well, the first coder didn't work, while the second did.


The first code has another problem due to the fact that cin's operator>> will pull in 2 characters even if you only typed 1 (the character you typed and a '\0' to terminate the string). If you are only trying to pull in 1 character, the cin.getc() would work better.

Nader Elshehabi wrote:
Yet, that makes a buffer of N chars. That's not what I want. What if the user inputs n+1 chars.


You will not be able to use the operator>> to do this (at least not yet ... as I said, the new proposal for the C++ standard has all overloaded operators that deal with char* now also overloaded for string). What you can do is iterate through it:

char ch;
string input;
while ((ch = cin.getc()) != '\n')
{
   input += ch;
}


That will prevent any possibility of a buffer overflow issue, but will also be VERY slow (in comparison to pulling down a whole set of data at once).


If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac

GeneralRe: Heap corruption?! Pin
Nader Elshehabi31-Aug-06 9:49
Nader Elshehabi31-Aug-06 9:49 
GeneralRe: Heap corruption?! Pin
David Crow31-Aug-06 10:09
David Crow31-Aug-06 10:09 
GeneralRe: Heap corruption?! Pin
Nader Elshehabi31-Aug-06 12:21
Nader Elshehabi31-Aug-06 12:21 
GeneralRe: Heap corruption?! Pin
Zac Howland31-Aug-06 10:20
Zac Howland31-Aug-06 10:20 
JokeRe: Heap corruption?! Pin
Nader Elshehabi31-Aug-06 12:29
Nader Elshehabi31-Aug-06 12:29 
GeneralRe: Heap corruption?! Pin
Stephen Hewitt31-Aug-06 14:10
Stephen Hewitt31-Aug-06 14:10 
GeneralRe: Heap corruption?! Pin
Zac Howland1-Sep-06 3:56
Zac Howland1-Sep-06 3:56 
GeneralRe: Heap corruption?! Pin
Stephen Hewitt1-Sep-06 4:19
Stephen Hewitt1-Sep-06 4:19 
GeneralRe: Heap corruption?! Pin
Zac Howland1-Sep-06 4:30
Zac Howland1-Sep-06 4:30 
AnswerRe: Heap corruption?! Pin
Jun Du31-Aug-06 8:20
Jun Du31-Aug-06 8:20 
GeneralRe: Heap corruption?! Pin
Nader Elshehabi31-Aug-06 9:06
Nader Elshehabi31-Aug-06 9:06 
AnswerRe: Heap corruption?! Pin
Stephen Hewitt31-Aug-06 14:07
Stephen Hewitt31-Aug-06 14:07 
GeneralRe: Heap corruption?! Pin
Nader Elshehabi1-Sep-06 5:22
Nader Elshehabi1-Sep-06 5:22 
Questionvoid main ... crashing Pin
jon-8031-Aug-06 7:12
professionaljon-8031-Aug-06 7:12 
AnswerRe: void main ... crashing Pin
Jun Du31-Aug-06 7:24
Jun Du31-Aug-06 7:24 
GeneralRe: void main ... crashing Pin
jon-8031-Aug-06 7:41
professionaljon-8031-Aug-06 7:41 
AnswerRe: void main ... crashing [modified] Pin
Chris Losinger31-Aug-06 7:43
professionalChris Losinger31-Aug-06 7:43 

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.