一个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;
这恰好在美国“有效”,但我不知道如果......假设法国用户正在运行此应用程序并开始输入奇怪的字符,例如会发生什么Ç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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)