Rohit Nagpal
Rohit Nagpal

Reputation: 79

Strange Output Encoding in WSL

I have created a program in C++ which uses wstring. The program is something like this:-

#include<iostream>
using namespace std;
const wstring NAME = L"STACKOVERFLOW";
int main()
{
    wcout<<NAME;
} 

Now, I have tried this program in windows and linux. The program is working on both platform correctly with output as STACKOVERFLOW but while using in wsl(Ubuntu), the output is very strange. It is something like this:-

 ?????r????????????????

I have two questions now:-

  1. Is this error related to Unicode? because I know that Windows have UTF-16 and Linux has UTF-32 for wchar whereas Wsl uses UTF-8.

  2. If it is related to Unicode, then how is it possible that it can work on Windows and linux but not in wsl since Windows and Linux have diffrent encoding.

P.S.:- If anybody has any idea, please do write your views.

Update:-

Recently, added a new line in the code and the output is like this now(in wsl):-

#include<iostream>
using namespace std;
const wstring NAME = L"STACKOVERFLOW";
int main()
{
  cout<<"Hello"<<endl; //outputting hello along with the widestring
  wcout<<NAME;
} 

and Now, The output is changed to this:-

Hello
SAKVRLW��pH�� �0�`� (�$p

Upvotes: 1

Views: 444

Answers (0)

Related Questions