-1

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
  • 5
    What happened when you tried to use getline? Is there a reason why you're using an array instead of std:: wstring? Commented Jan 16, 2023 at 11:05

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.