Click here to Skip to main content
15,907,493 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: strcpy and CString question Pin
Nish Nishant1-Oct-02 4:46
sitebuilderNish Nishant1-Oct-02 4:46 
GeneralRe: strcpy and CString question Pin
ns1-Oct-02 4:52
ns1-Oct-02 4:52 
GeneralRe: strcpy and CString question Pin
Michael Dunn1-Oct-02 5:17
sitebuilderMichael Dunn1-Oct-02 5:17 
GeneralRe: strcpy and CString question Pin
Jon Hulatt1-Oct-02 5:30
Jon Hulatt1-Oct-02 5:30 
GeneralRe: strcpy and CString question Pin
Jon Hulatt1-Oct-02 5:35
Jon Hulatt1-Oct-02 5:35 
GeneralRe: strcpy and CString question Pin
Nitron1-Oct-02 5:31
Nitron1-Oct-02 5:31 
GeneralRe: strcpy and CString question Pin
Nish Nishant1-Oct-02 5:38
sitebuilderNish Nishant1-Oct-02 5:38 
GeneralRe: strcpy and CString question Pin
JT Anderson1-Oct-02 5:41
JT Anderson1-Oct-02 5:41 
In an attempt to clarify and emphasize Michael's response...

The explicit and gratuitous cast than Nish suggests is very bad practice. The original poster's code was entirely correct.

As Michael said, CString has a conversion operator to LPCTSTR (aka "const char *"). The second argument to strcpy is a const char *, not a char *, so the implicit conversion occurs and everybody's happy.

The gratuitous cast that Nish suggested is unnecessary and could later hide errors introduced by subsequent changes to the code. NEVER USE EXPLICIT CASTS UNLESS YOU ABSOLUTELY MUST!

I might add that the whole idea of allocating this buffer to a dumb pointer and then copying the string into it is quite questionable. We'd need more context to know whether or not there is any justification for it.
GeneralRe: strcpy and CString question Pin
Nish Nishant1-Oct-02 5:54
sitebuilderNish Nishant1-Oct-02 5:54 
GeneralRe: strcpy and CString question Pin
Michael Dunn1-Oct-02 7:48
sitebuilderMichael Dunn1-Oct-02 7:48 
GeneralRe: strcpy and CString question Pin
Rene De La Garza1-Oct-02 10:39
Rene De La Garza1-Oct-02 10:39 
GeneralRe: strcpy and CString question Pin
Michael Dunn1-Oct-02 14:07
sitebuilderMichael Dunn1-Oct-02 14:07 
GeneralRe: strcpy and CString question Pin
Rene De La Garza1-Oct-02 16:27
Rene De La Garza1-Oct-02 16:27 
GeneralRe: strcpy and CString question Pin
Ravi Bhavnani1-Oct-02 5:27
professionalRavi Bhavnani1-Oct-02 5:27 
GeneralRe: strcpy and CString question Pin
Jon Hulatt1-Oct-02 5:34
Jon Hulatt1-Oct-02 5:34 
GeneralRe: strcpy and CString question Pin
Ravi Bhavnani1-Oct-02 6:54
professionalRavi Bhavnani1-Oct-02 6:54 
GeneralRe: strcpy and CString question Pin
Michael Dunn1-Oct-02 7:50
sitebuilderMichael Dunn1-Oct-02 7:50 
GeneralDocument/View startup problem Pin
will13831-Oct-02 4:32
will13831-Oct-02 4:32 
GeneralRe: Document/View startup problem Pin
Tomasz Sowinski1-Oct-02 5:58
Tomasz Sowinski1-Oct-02 5:58 
GeneralRe: Document/View startup problem Pin
will13831-Oct-02 6:46
will13831-Oct-02 6:46 
GeneralRe: Document/View startup problem Pin
Tomasz Sowinski1-Oct-02 6:55
Tomasz Sowinski1-Oct-02 6:55 
GeneralRe: Document/View startup problem Pin
will13831-Oct-02 7:29
will13831-Oct-02 7:29 
GeneralRe: Document/View startup problem Pin
Tomasz Sowinski1-Oct-02 8:23
Tomasz Sowinski1-Oct-02 8:23 
QuestionWhy does my app close right after starting if i add an IP Address Control? Pin
Anonymous1-Oct-02 4:32
Anonymous1-Oct-02 4:32 
AnswerRe: Why does my app close right after starting if i add an IP Address Control? Pin
Nish Nishant1-Oct-02 5:02
sitebuilderNish Nishant1-Oct-02 5:02 

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.