Click here to Skip to main content
15,919,358 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How can I convert TCHAR to string in C++?

Thanks in advance.
Posted
Comments
Richard MacCutchan 7-Aug-10 4:15am    
What do you mean by convert, convert to what? TCHAR is a single character, do you actually mean an array of TCHARs? Please try a better explanation of your problem.
Richard MacCutchan 28-Mar-13 6:43am    
Look at the date of this question!
raghunath sahoo 3-Apr-13 11:14am    
tchar* to string^ to be specific.
Lets say TCHAR* name = L"Hello";
So for my CLR implementaion I need it to convert it to String^. I have found a solution to convert from string to String^. If any body can provide me the solution to convert from TCHAR* to std::string atleast?
Richard MacCutchan 3-Apr-13 11:50am    
Why are you posting in here? You already have a question of your own open, where I gave you a suggestion. Please stick to your own question, and update its contents if necessary.
Richard MacCutchan 28-Mar-13 6:30am    
How did you select this question?

Have a look at this discussion thread[^]. Looks like a similar issue was posted there.
 
Share this answer
 
TCHAR can be char or wchar_t depends on your project character settings.
if it is unicode char seettings it will be wchar_t else it will be char.

you can hold TCHAR* in a CString.

TCHAR* pstrName = _T("MY Name");
CString str = pstrName;

if you are using stl then try following code.
<br />
TCHAR* pstName = _T("My Name");<br />
//std::string is a type of basic_string<br />
std::basic_string<TCHAR> strName = pstName;<br />
 
Share this answer
 
See What are TCHAR, WCHAR, LPSTR, LPWSTR, LPCTSTR (etc.)?[^]for a detailed article about the various string types in C++ and how to convert one into another.
 
Share this answer
 
Comments
Richard MacCutchan 28-Mar-13 6:30am    
Did you notice the date on this question, do you think he/she is still waiting for an answer?
nv3 28-Mar-13 6:39am    
Oops, I guess he has found the solution by now -- or he is found another job :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900