| | |
How to LPCTSTR Convert to char *
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
No. LPCTSTR is defined as const char *. No conversion needed except typecasting to remove the const attribute. Depending upon what is going to be done this may or may not be a good idea.
Example:
Example:
C++ Syntax (Toggle Plain Text)
int main() { LPCTSTR s = "Hello"; char *p = const_cast<char*>(s); return 0; }
Last edited by Ancient Dragon; Dec 6th, 2006 at 12:14 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Jul 2006
Posts: 14
Reputation:
Solved Threads: 0
•
•
•
•
No. LPCTSTR is defined as const char *. No conversion needed except typecasting to remove the const attribute. Depending upon what is going to be done this may or may not be a good idea.
Example:
C++ Syntax (Toggle Plain Text)
int main() { LPCTSTR s = "Hello"; char *p = const_cast<char*>(s); return 0; }
LPCTSTR s = _T("Hello");
char *p = const_cast<char*>(s);
error C2440: 'const_cast' : cannot convert from 'LPCTSTR' to 'char *'
help me ,thank you
are you compiling for UNICODE. If you are using VC++ 2005 that is the default.
If yes, then typecasting won't work. you have to use a conversion function to convert from wchar_t* to char*
If yes, then typecasting won't work. you have to use a conversion function to convert from wchar_t* to char*
Last edited by Ancient Dragon; Dec 6th, 2006 at 1:06 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: IP address
- Next Thread: Sparce Matrices
| Thread Tools | Search this Thread |
api array based beginner bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






