私は何か非常に簡単ですが、私は文字入力のためにユーザーに入力を促しています&文字を文字列に保存します。それから私はその全体の文字列を印刷します。wstringにTCHARを追加する:動作しません
プログラムはウィンドウ用ですが、私はASCIIの&ユニコードのためにプログラムを動作させたいので、私はユーザーTCHAR、& wstringです。
私の問題:文字(ユーザーが入力したもの)をwstringに追加できません。その変数には格納されません。どうして?
私の簡単なコード:
#include <windows.h>
#include <tchar.h>
#include <conio.h>
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
int main()
{
// I am using wstring for unicode compatibility but in Windows(MSDN) is there a general
// string variable? You know how there is char, wchar & then TCHAR(which is a general variable
// for both ASCII & unicode). Is there a TSTRING or something?
wstring chStr = L"abc";
TCHAR ch = L'a';
while (ch != '!')
{
printf("Enter a character: ");
ch = getch();
chStr += ch; // the string never takes on a char it always remains as "a"
printf("\nThe characters entered so far are: %s \n", chStr.c_str());
}
system("PAUSE");
return 0;
}
なぜASCIIサポートが必要ですか?あなたはまだWindows 3を使用していますか? –
'std :: tstring'はありません。あなたはこれを行うことができます: 'typedef std :: basic_string tstring' –
Nubcase
' TCHAR'は 'char'か' wchar_t'のどちらかのtypedefですので、何とかそれを考慮する必要があります。ここでは、ワイドチャールの一般性に関する私の[少し暴言](http://stackoverflow.com/questions/6300804/wchars-encodings-standards-and-portability)です。 –