visual c++中支持unicode char的从TCHAR到char*的转换
visual Conversion from TCHAR to char* with unicode char support in c++
如何用unicode字符将TCHAR转换为char*。我使用以下代码
//BROWSE FOLDER - Opens a browse folder dialog.
char* browse_folder(void)
{
char *selected_path = NULL;
TCHAR path[MAX_PATH];
BROWSEINFO bi = { 0 };
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI;
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
if (pidl != 0)
{
// get the name of the folder and put it in path
SHGetPathFromIDList(pidl, path);
//Set the current directory to path
SetCurrentDirectory(path);
// free memory used
IMalloc* imalloc = 0;
if (SUCCEEDED(SHGetMalloc(&imalloc)))
{
imalloc->Free(pidl);
imalloc->Release();
}
//selected_path = ;
USES_CONVERSION;
selected_path = T2A(path);
}
}
我在visual studio项目设置中启用了unicode。我使用此函数来浏览文件夹,当我将其转换为char* unicode字符被替换为(?????)符号时,我在路径(TCHAR)中获得确切的值。
由于您的项目支持unicode字符,您应该使用WideCharToMultiByte()将其转换为char*。
相关文章:
- 将无符号char*转换为std::istream*C++
- 为什么这个函数将"const char*"转换为"void* const"而不是"const void*"
- 将函数参数"const char*"转换为"std::string_view"是
- C ++如何在使用"tolower"时将char转换为int
- 有没有办法在C++的赋值中将"char**"转换为"double"?
- JavaCPP 错误:无法将参数"1"的"char*"转换为"Abc*
- 为什么从 char 转换为 std::byte 可能是未定义的行为?
- 如何在虚幻引擎4中将char*转换为TCHAR?
- C++:将模板类型 char 转换为 std::string
- strcmp/char* 转换无法按预期工作
- C++中的SQLite char*转换
- 无法从 const char* 转换为 const char *&
- 在 C++ 中将 char 转换为 int,而无需符号位传播
- 如果必须包含西里尔字符,如何将 char* 转换为 std::string?
- 试图使用strCMP时的char转换错误
- 无法从'const char *'转换为'LPCTSTR'
- 将 std::vector<char> 转换为字符* 会导致字符缺陷
- 使用 static_cast 将 char 转换为 int c++
- 如何在 C++(MFC) 中将 char* 转换为 LPCTSTR
- 无法将const char转换为字符串构造字符串