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
。入力の最大長は常に十分に長く設定できますが、理想的には、ユニコードと非ユニコードのエントリを同じ文字数に制限したいと考えています。うまくいけば、そうすることはかなり簡単でエレガントです。