Convert CString to char*
-
I'm trying to find an easy way to convert a CString to a char* without having to do it character-by-character. I've tried memcpy unsuccessfully. Anyone have any tricks?
-
I'm trying to find an easy way to convert a CString to a char* without having to do it character-by-character. I've tried memcpy unsuccessfully. Anyone have any tricks?
CString provides a (LPCTSTR) cast operator for this.BTW, what are you trying to achieve ? can't you just use CString::operator[]() or CString::GetAt() to retrieve a character in the CString object ?
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
CString provides a (LPCTSTR) cast operator for this.BTW, what are you trying to achieve ? can't you just use CString::operator[]() or CString::GetAt() to retrieve a character in the CString object ?
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
I want to get the entire string into a char array in case I can't figure out how to do something else.
-
I'm trying to find an easy way to convert a CString to a char* without having to do it character-by-character. I've tried memcpy unsuccessfully. Anyone have any tricks?
This thread may be of use. Regards, --Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia Introduction to Object-Oriented JavaScript
-
This thread may be of use. Regards, --Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia Introduction to Object-Oriented JavaScript
You rock.
-
I want to get the entire string into a char array in case I can't figure out how to do something else.
-
This thread may be of use. Regards, --Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia Introduction to Object-Oriented JavaScript
NO, definitely not !
GetBuffer()
is not there for casting purpose ! Moreover, the OP seem not to really know what he wants that for, so instead of saying amen to a query-for-code, better understand why such a thing is asked for... I'm more likely to think he's trying to iterate on every characters of the string, so no need for cast for this ; a simple use of the[]
operator would do ! BTW, I'm almost certain that Roger Allen (which is also a great codeproject member) would not reply so nowadays... notice that he replied so, but it was in year 2000 ! at last, read this[^] and tell me if you see somewhere in Microsoft recomendations to useGetBuffer()
.[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
modified on Friday, August 22, 2008 11:16 AM
-
You rock.
USAFHokie80 wrote:
You rock
Probably, but certainly not on this post... please read my answer to him[^]
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
super_ttd wrote:
what do you want to do that for ?
exactly. As I am suspecting the OP to have asked this for a darken reason, I'm not sure casting the CString object would be worth it...
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
NO, definitely not !
GetBuffer()
is not there for casting purpose ! Moreover, the OP seem not to really know what he wants that for, so instead of saying amen to a query-for-code, better understand why such a thing is asked for... I'm more likely to think he's trying to iterate on every characters of the string, so no need for cast for this ; a simple use of the[]
operator would do ! BTW, I'm almost certain that Roger Allen (which is also a great codeproject member) would not reply so nowadays... notice that he replied so, but it was in year 2000 ! at last, read this[^] and tell me if you see somewhere in Microsoft recomendations to useGetBuffer()
.[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
modified on Friday, August 22, 2008 11:16 AM
I was merely posting a link to a thread that was of the same subject - I was not involved with any of those thread posts I thought it would be helpful to USAFHokie80 here.. Regards, --Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia Introduction to Object-Oriented JavaScript
-
I was merely posting a link to a thread that was of the same subject - I was not involved with any of those thread posts I thought it would be helpful to USAFHokie80 here.. Regards, --Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia Introduction to Object-Oriented JavaScript
Yeah... GetBuffer doesn't work. But this works: char* str = (char*)(LPCTSTR)str2
-
NO, definitely not !
GetBuffer()
is not there for casting purpose ! Moreover, the OP seem not to really know what he wants that for, so instead of saying amen to a query-for-code, better understand why such a thing is asked for... I'm more likely to think he's trying to iterate on every characters of the string, so no need for cast for this ; a simple use of the[]
operator would do ! BTW, I'm almost certain that Roger Allen (which is also a great codeproject member) would not reply so nowadays... notice that he replied so, but it was in year 2000 ! at last, read this[^] and tell me if you see somewhere in Microsoft recomendations to useGetBuffer()
.[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
modified on Friday, August 22, 2008 11:16 AM
toxcct wrote:
Moreover, the OP seem not to really know what he wants that for, so instead of saying amen to a query-for-code, better understand why such a thing is asked for...
better understand stuff! BAH, we don't need no freakin understanding we just writ cods plezzzzz :laugh:
led mike
-
Yeah... GetBuffer doesn't work. But this works: char* str = (char*)(LPCTSTR)str2
USAFHokie80 wrote:
Yeah... GetBuffer doesn't work.
hum, correction : GetBuffer DOES work, but it's not there for that. ;P
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
toxcct wrote:
Moreover, the OP seem not to really know what he wants that for, so instead of saying amen to a query-for-code, better understand why such a thing is asked for...
better understand stuff! BAH, we don't need no freakin understanding we just writ cods plezzzzz :laugh:
led mike
lol... was it urgentz ? I didn't read so, so it means I had time to think about design ! :laugh:
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Yeah... GetBuffer doesn't work. But this works: char* str = (char*)(LPCTSTR)str2
That's a horrible cast, and a good example why casts are bad. If you needed the cast to get that to compile then you did something wrong. It should be const char* str = str2; If your CString is always based on a "char" character type, then you should be using a CStringA. Mixing generic and fixed character types negates the usefulness of generic character types (i.e. your code will fail on a Unicode build). Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: