I have something pretty simple to do, I am trying to prompt the user for character input & save that character onto a string. Then I print that whole string.
The program is for windows but I want the program to work for both ASCII & Unicode which is why I user TCHAR, & wstring.
My Problem: I am unable to add the character(that the user inputs) onto a wstring. It just wont be stored in that variable. Why?
My simple code:
#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;
}