# Handling WCHAR TCHAR LPCTSTR LPSTR CSTRING CHAR*

This topic is 3913 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Halo i'm so confused in data type of string in VC++ especially data type from Windows I know there are any thread tells about it..somewhere but not complex Main : How can i handle WCHAR,TCHAR,LPCTSTR,LPSTR,CString,CHAR* or more like converting,creating,deleting,concatenation etc? 1. What header must be included? 2. why <windows.h> and <strsafe.h> when i use Cstring....$#$%#$% Error... bah 3. i try mfc, what kind of data type of string allowed 4. i use vc++ 2003,i don't know what exactly about : L"anystring" There are many problems handling them. So please just tell me EVERYTHING you know about them. By the way,I often switch use VC++ 2003 or VC++ 6 Thanks very much for your help. Thanks....thanks...thanks.... #### Share this post ##### Link to post ##### Share on other sites Advertisement Quote:  By the way,I often switch use VC++ 2003 or VC++ 6 This would be your first mistake. Use MVS 2005 and forget about both of those. Which string to choose? Which one do you need? C++ has exactly one: std::string. Use that for everything, unless you can't. Windows API uses the LPGHASYGFYHSTR and LFHJSIYUGERBKSDFBJUERS and all the other hungaric notation @#$&*\$# types.
MFC provides its own (is it CString?)
char * is C legacy, and shouldn't be used if given other options.
L"" is the unicode conversion for strings.

Use the one that is most suitable for the application you're developing. When that is not enough, use the one that is mandated by your API.

If you're not using UI of any kind, then use std::string exclusively. That one provides c_str() conversion to const char *.

Which headers to include is clearly stated in documentation on per-class basis. For MFC or other frameworks, headers might be auto-generated, or included through other means. It all depends on how particular library defines them.

Operations on strings are also defined based on the type you use. You'll need to look up the facilities provided for the type of application you're developing.

Quote:

Can you pay for 3 years of my time?

##### Share on other sites
LPSTR = CHAR*
LPWSTR = WCHAR*
LPTSTR = TCHAR*

LPCSTR = const CHAR*
LPCWSTR = const WCHAR*
LPCTSTR = const TCHAR*

W means wide char (unicode)

lack of W or T means single byte characters (ansi)

T means either W or "lack of W", depending on if UNICODE is #defined. You'd use this if you wanted to build for non-unicode and unicode versions of your app.

If your app will always be unicode, or always not unicode, then just always use the W versions, or the "lack of W or T" versions respectively.

• 48
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631374
• Total Posts
2999661
×