Ham*_*jan 4 c++ string unicode atl utf-16
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;
Run Code Online (Sandbox Code Playgroud)
这恰好在美国“工作”,但我不知道如果......说法国用户正在运行这个应用程序并开始输入奇怪的字符,例如Çanemeplaîtpas.xml 在命令行上会发生什么。我正在寻找一种干净的方法来填充该CAtlString类型的字符串。输入的最大长度总是可以设置得足够长,但理想情况下我想将 unicode 和非 unicode 条目限制为相同数量的字符。希望这样做相当容易和优雅。
如果您期望 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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4332 次 |
| 最近记录: |