wchar_t user input with spaces

112 Views Asked by At

Im currently using wchar_t for a username, however, I'm having an issue when the username contains a space when using std::wcout as it will just get the first word typed. I am aware of getline for when your user input contains a space but I can't get it to work with the wchar_t. I don't suppose anyone could help or point me in the right direction?

Here is the code I have currently:

                

wchar_t window_title[50] = L"Krogex: ";                
  std::cout << "Input window " << i + 1 << "s username: " << std::endl; 
    wchar_t username[20]; 
    std::wcin >> username;
1

There are 1 best solutions below

0
user20716902 On

Here is how to use getline with a wstring; this will allow you to enter a username with spaces.

wchar_t window_title[50] = L"Krogex: ";
std::cout << "Input window " << i + 1 << "s username: " << std::endl;
std::wstring username;
std::getline(std::wcin, username);