CString to LPCSTR.
-
hi all, i want to convert CString to LPCSTR. /===================================== CString str = "Hellow this is a Text"; LPCSTR result[150]; -->how we get the str value in result ?. i.e result = "Hellow this is a Text". //==================================== Please let me know if any solution for this. its urgent for me
Uday kiran
-
hi all, i want to convert CString to LPCSTR. /===================================== CString str = "Hellow this is a Text"; LPCSTR result[150]; -->how we get the str value in result ?. i.e result = "Hellow this is a Text". //==================================== Please let me know if any solution for this. its urgent for me
Uday kiran
uday kiran janaswamy wrote:
CString str = "Hellow this is a Text"; LPCSTR result[150]; -->how we get the str value in result ?. i.e result = "Hellow this is a Text".
You can't use LPCSTR here because of the constantness. But how about this:
LPTSTR result[150]; _tcsncpy(result, str.GetString(), 150);
hth, Christof -
uday kiran janaswamy wrote:
CString str = "Hellow this is a Text"; LPCSTR result[150]; -->how we get the str value in result ?. i.e result = "Hellow this is a Text".
You can't use LPCSTR here because of the constantness. But how about this:
LPTSTR result[150]; _tcsncpy(result, str.GetString(), 150);
hth, Christofhi christopher, i am getting this type of error as i copy your code. please help me out. '_tcsncpy' : cannot convert parameter 1 from 'LPSTR [150]' to 'char *
Uday kiran
-
hi all, i want to convert CString to LPCSTR. /===================================== CString str = "Hellow this is a Text"; LPCSTR result[150]; -->how we get the str value in result ?. i.e result = "Hellow this is a Text". //==================================== Please let me know if any solution for this. its urgent for me
Uday kiran
From MSDN // example for CString::GetBuffer CString s( "abcd" ); #ifdef _DEBUG afxDump << "CString s " << s << "\n"; #endif LPTSTR p = s.GetBuffer( 10 ); strcpy( p, "Hello" ); // directly access CString buffer s.ReleaseBuffer( ); #ifdef _DEBUG afxDump << "CString s " << s << "\n"; #endif
-
hi all, i want to convert CString to LPCSTR. /===================================== CString str = "Hellow this is a Text"; LPCSTR result[150]; -->how we get the str value in result ?. i.e result = "Hellow this is a Text". //==================================== Please let me know if any solution for this. its urgent for me
Uday kiran
-
hi all, i want to convert CString to LPCSTR. /===================================== CString str = "Hellow this is a Text"; LPCSTR result[150]; -->how we get the str value in result ?. i.e result = "Hellow this is a Text". //==================================== Please let me know if any solution for this. its urgent for me
Uday kiran
why don't you just do :
CString str = "hello world";
(LPCSTR)str; // used as you like
// either used with strcpy to be copied, or passed as a function parameter
Don't know where to start ?
Refer the Forums Guidelines and ask a friend -
hi christopher, i am getting this type of error as i copy your code. please help me out. '_tcsncpy' : cannot convert parameter 1 from 'LPSTR [150]' to 'char *
Uday kiran
The person that replied to you made a typo, the code should be:
TCHAR result[150];
_tcsncpy(result, str.GetString(), 150);If you are using a
CString
, you there is a built in operator that will return anLPCTSTR
, so you do not have to useGetBuffer(...)
or anything like that to get a const pointer. Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
why don't you just do :
CString str = "hello world";
(LPCSTR)str; // used as you like
// either used with strcpy to be copied, or passed as a function parameter
Don't know where to start ?
Refer the Forums Guidelines and ask a friendThank you very much.
Uday kiran
-
uday kiran janaswamy wrote:
CString str = "Hellow this is a Text"; LPCSTR result[150]; -->how we get the str value in result ?. i.e result = "Hellow this is a Text".
You can't use LPCSTR here because of the constantness. But how about this:
LPTSTR result[150]; _tcsncpy(result, str.GetString(), 150);
hth, ChristofMass Nerder wrote:
_tcsncpy(result, str.GetString(), 150);
When using a method that is specific to a particular VC++ version, it helps to state such.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb