Why is the emoji displays incorrectly in Windows Terminal? - c++

I try to use C++ to output a emoji and below is the code. I wrote this in VS Code.
#include <iostream>
int main() {
std::cout << "😊";
return 0;
}
Then I try to compile this code with Clang++ and get a .exe file. But when I run the .exe file in Windows Terminal it doesn't display correctly.
Below is what I get when I run the file.
PS C:\Users\26354> D:\Code_exercise\Assignment\Class\Bin\Temp.exe
馃槉
PS:
Clang version 13.0.1
Target: x86_64-pc-windows-msvc
Windows Terminal Version: 1.12.10393.0
VS Code Version: 1.64.2
Windows Version: Windows 10 Pro 21H2

Related

gdb <error reading variable> for any string object

Lets take this very simple program here for example:
// test.cpp
#include <string>
#include <iostream>
using namespace std;
int main() {
string str = "Hello";
cout << str << endl;
return 0;
}
now I compile this code with g++ compiler:
g++ -g test.cpp -o test.exe
now I am trying to debug this with gdb:
gdb test.exe
after I set breakpoint on main and then reach the line return 0, I try to see what is in the string str. But I cannot print it in the console. It says <error reading variable>. Not only in gdb console, even Visual Studio Code UI using gdb gives the same output.
Here is a screenshot of my console:
I have searched for this everywhere and the only relevant question I found was this, which did not work.
I also found this post on github VS Code repo issues. The fix suggested there might work I am not sure, I cannot find the setting that he suggested on my Windows 11 machine.
How do I read the value in the string in debug mode?
Edit
After #ssbssa suggested me to update my gcc, I used MSYS2 to get the latest gcc, g++, and gdb versions. Now I have gdb 12.1. Now it is not showing the old error anymore but now it says "Converting character sets: Invalid argument". Still struggling to get it to work.
First run your program with gdb like so:
gdb test.exe
Now inside the command line interface run the command:
set charset UTF-8
This should temporarily fix your problem. The only inconvenience might be that you need to run this line every time you debug on your command prompt with GDB.
I noticed that you are also using Visual Studio Code. You can install C++ extensions for VS Code and there you can add the command set charset UTF-8 in the launch.json setupCommands array as shown here. This way you can debug your application faster.

std::codecvt_utf8 facet erroneous output with MSYS2 Bash and CMD

Reproduce: codecvt.cpp
#include <iostream>
#include <locale>
#include <string>
#include <codecvt>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
locale utf8(locale(), new codecvt_utf8<wchar_t>);
wcout.imbue(utf8);
wstring str(L"Test String OÖ UÜ SŞ iİ ıI");
wcout << str << '\n';
}
Compile with GCC 6.3.0: g++ codecvt.cpp -o codecvt -O3
Windows CMD: codecvt.exe
Output: Test String O├û U├£ S┼Ş i─░ ─▒I
MSYS2 Bash: $ ./codecvt.exe
Output: Test String O├û U├£ S┼Ş i─░ ─▒I (same)
Ubuntu subsystem for Windows 10 Bash:
Compile with GCC 5.4.0: g++ codecvt.cpp -o codecvt -O3
Execute: ./codecvt
Output: Test String OÖ UÜ SŞ iİ ıI
I've been struggling with wide character problems in c++ lately. I ran into this solution but code only seems to be working in linux environment. (I am a c++ beginner (ish))
I also tried some other solutions:
First solution:
setlocale(LC_ALL, "");
Windows CMD outputs as desired, no problems. But input is erroneous.
MSYS2 Bash does not outputs as desired, but input is correct.
Ubuntu subsystem for Windows 10 Bash is correct with both input and output.
Second solution:
locale::global(locale("C.UTF-8"));
Both Windows CMD and MSYS2 Bash crashes at start of program, MSYS2 Bash also reported:
what(): locale::facet::_S_create_c_locale name not valid
Ubuntu subsystem Bash is still cool, works for input/output correcly.
I am guessing this is a problem related to Windows?

how to compile c++ program in mac terminal

i wrote a program in my mac using sublime text as the plateform..
#include<iostream>
using namespace std;
int main()
{
cout<<"HELLOW WORLD";
return 0;
}
this was my program..
i saved it in desktop as hellow.cpp
while compiling on mac terminal as g++ hellow.cpp, i found an error
adarshs-MacBook-Air:Desktop adarshak$ g++ hellow.cpp
xcrun: error: invalid active developer path
(/Library/Developer/CommandLineTools), missing xcrun at:
/Library/Developer/CommandLineTools/usr/bin/xcrun
anyone plese help me to find out the error
It sounds like you don't have the command line developer tools installed. Run this command from Terminal once:
xcode-select --install
This will bring up the download & installation UI. Follow this through to the end. (It may take a while depending on the speed of your internet connection.)
From then on compiling should work.

How to build an Xcode c++ program on terminal

I am using Xcode to program c++ projects. I am using ncurses library.
I am create a simple example, which works fine on terminal, but it does not work using xcode.
#include<ncurses.h>
#include<iostream>
int main()
{
char c;
initscr();
printw("Hello world!");
refresh();
c=getch();
endwin();
return 0;
}
On Xcode I get this error
Error opening terminal: unknown.
I am wondering that Xcode is not able to emulate an terminal. So, I try to change the "build phase" in xcode in order to build my project on terminal. I have used the proposed solution Automatically open terminal when debugging in Xcode?
But my project continue to run on xcode. What is the problem?

OS X 10.6.4 + Eclipse 3.5 + latest CDT not outputting cout/printf to console

I spend most of my time in Eclipse these days, so I thought I would check out what Eclipse's C++ support was like (I usually use Xcode on Mac and Visual Studio for Windows).
I found the CDT package for Eclipse 3.5, so I installed it.
Everything installed properly and the default C++ "Hello World" project compiled nicely, however for the life of me I can't get any application output piped to the console. I've tried everything, and searched around for solutions, but it seems I'm not the only one. Most have trouble in Windows, but I haven't seen a lot of issues with OS X.
Of course, if I run the compiled output in a bash shell, it displays output properly.
This is how simple the default app is:
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
printf("Hello world");
return 0;
}
Any ideas?
Cheers,
Shane
Just tried this in Helios 3.6 and it works. Must be a 3.5 problem.