如何将TCHAR数组转换为std::string(而不是std::basic_string)? 最佳答案 TCHAR只是一个typedef,根据您的编译配置,默认为char或wchar_t。标准模板库支持ASCII(使用std::string)和宽字符集(使用std::wstring)。您需要做的就是根据您的编译配置将typedefString作为std::string或std::wstring。为了保持灵active,您可以使用以下代码:#ifndefUNICODEtypedefstd::stringString;#elsetyp
如何将TCHAR数组转换为std::string(而不是std::basic_string)? 最佳答案 TCHAR只是一个typedef,根据您的编译配置,默认为char或wchar_t。标准模板库支持ASCII(使用std::string)和宽字符集(使用std::wstring)。您需要做的就是根据您的编译配置将typedefString作为std::string或std::wstring。为了保持灵active,您可以使用以下代码:#ifndefUNICODEtypedefstd::stringString;#elsetyp
例如://ThiswillbecomeeitherSomeMethodAorSomeMethodW,//dependingonwhether_UNICODEisdefined.SomeMethod(_T("MyStringLiteral"));//BecomeseitherAnotherMethodAorAnotherMethodW.AnotherMethod(_TEXT("MyText"));我都见过。_T似乎是为了简洁而_TEXT是为了清楚起见。这仅仅是程序员的主观偏好还是比这更具技术性?例如,如果我使用其中一个,我的代码会不会针对特定系统或某些旧版本的头文件编译?
例如://ThiswillbecomeeitherSomeMethodAorSomeMethodW,//dependingonwhether_UNICODEisdefined.SomeMethod(_T("MyStringLiteral"));//BecomeseitherAnotherMethodAorAnotherMethodW.AnotherMethod(_TEXT("MyText"));我都见过。_T似乎是为了简洁而_TEXT是为了清楚起见。这仅仅是程序员的主观偏好还是比这更具技术性?例如,如果我使用其中一个,我的代码会不会针对特定系统或某些旧版本的头文件编译?