如何将“wchar_t *”转换为“const char *”

时间:2022-12-04 05:52:56

How can I convert 'wchar_t *' to 'const char *' ?

如何将“wchar_t *”转换为“const char *”?

using C++ MFC VS2010.

使用c++ MFC VS2010。

Thank you.

谢谢你!

2 个解决方案

#1


9  

Look up the functionality of wcstombs on MSDN.

在MSDN上查找wcstombs的功能。

#2


6  

As the question is about MFC, I would suggest the following:

由于问题是关于MFC,我建议如下:

CStringA a = "Test";
CStringW w = L"Test";
a = CStringA(w);
w = CStringW(a);

I typically need the following conversions:

我通常需要以下转换:

CString t = _T("Test"); // depends on TCHAR type
a = CStringA(t); // does not depend on TCHAR type
w = CStringW(t);

CStringW and CStringA have operators LPCWSTR and LPCSTR respectivelly.

CStringW和CStringA分别有LPCWSTR和LPCSTR操作符。

#1


9  

Look up the functionality of wcstombs on MSDN.

在MSDN上查找wcstombs的功能。

#2


6  

As the question is about MFC, I would suggest the following:

由于问题是关于MFC,我建议如下:

CStringA a = "Test";
CStringW w = L"Test";
a = CStringA(w);
w = CStringW(a);

I typically need the following conversions:

我通常需要以下转换:

CString t = _T("Test"); // depends on TCHAR type
a = CStringA(t); // does not depend on TCHAR type
w = CStringW(t);

CStringW and CStringA have operators LPCWSTR and LPCSTR respectivelly.

CStringW和CStringA分别有LPCWSTR和LPCSTR操作符。