如何阅读用户';将控制台的输入转换为Unicode字符串? 一个C++初学者的问题。以下是我目前的情况: // From tchar.h #define _T(x) __T(x) ... // From tchar.h #defin
如何阅读用户';将控制台的输入转换为Unicode字符串?如何阅读用户';将控制台的输入转换为Unicode字符串? 一个C++初学者的问题。以下是我目前的情况: // From tchar.h #define _T(x) __T(x) ... // From tchar.h #defin,c++,string,unicode,atl,utf-16,C++,String,Unicode,Atl,Utf 16,如何阅读用户';将控制台的输入转换为Unicode字符串? 一个C++初学者的问题。以下是我目前的情况: // From tchar.h #define _T(x) __T(x) ... // From tchar.h #define __T(x) L ## x ... // In MySampleCode.h #ifdef _UNICODE #define tcout wcout #else #define tcout cout #endi
一个C++初学者的问题。以下是我目前的情况:
// From tchar.h
#define _T(x) __T(x)
...
// From tchar.h
#define __T(x) L ## x
...
// In MySampleCode.h
#ifdef _UNICODE
#define tcout wcout
#else
#define tcout cout
#endif
...
// In MySampleCode.cpp
CAtlString strFileName;
if (bIsInteractiveMode)
{
char* cFileName = new char[513];
tcout << endl;
tcout << _T("Enter the path to a file that you would like to XYZ(purpose obfuscated) ") << endl;
tcout << _T(">>> ");
cin.getline(cFileName, 512);
strFileName = cXmlFileName;
}
// Demonstrates how CAtlString can be printed using `tcout`.
tcout << _T("File named '") << strFileName.GetString() << _T("' does not exist.") << endl;
//来自tchar.h
#定义ut(x)ut(x)
...
//来自tchar.h
#定义uu T(x)L##x
...
//在MySampleCode.h中
#ifdef_UNICODE
#定义tcout wcout
#否则
#定义输出cout
#恩迪夫
...
//在MySampleCode.cpp中
CAtlString strFileName;
if(交互模式)
{
char*cFileName=新字符[513];
t如果希望使用unicode输入,您不应该在流中使用wcin吗
#include <iostream>
#include <string>
#include <locale>
int main()
{
using namespace std;
std::locale::global(locale("en_US.utf8"));
std::wstring s;
std::wcin >> s;
std::wcout << s;
}
#包括
#包括
#包括
int main()
{
使用名称空间std;
std::locale::global(locale(“en_US.utf8”);
std::wsts环;
std::wcin>>s;
std::wcout这里有一个类似的问题:是的,谢谢。答案指的是std::wstring
和std::string
。但是,我想使用ATL字符串。与问题无关,我想你应该这样定义你的cFileName:char*cFileName=new char[MAX_PATH];由于它是一个路径,您应该有MAX_path,请提供一个比较完整的代码示例-我很乐意!