Console output in cmd.exe and powershell.exe via C ++

I know a simple way to correctly display localized characters on Cmd.exe . But how can I do the same for Powershell.exe ?

 #include<iostream> #include<windows.h> using namespace std; int main() { SetConsoleCP(GetACP()); SetConsoleOutputCP(GetACP()); // valid output in cmd.exe, // but invalid output in powershell.exe cout << "  (1)!" << endl; // invalid output in both variants: cmd.exe, // and powershell.exe wcout << L"  (2)!" << endl; return 0; } 
+4
source share
2 answers

What is the conclusion? Does your font support these glyphs?

perhaps the following link might be useful (about cmd.exe):

http://www.watchingthenet.com/how-to-add-and-change-fonts-in-windows-command-prompt.html

You can also try redirecting the output from powershell to a file and checking this. If the file is correct, you have a console font that does not support your characters.

there is also a ms blog showing how to customize the font (about ps)

http://blogs.msdn.com/b/powershell/archive/2006/10/16/windows-powershell-font-customization.aspx

0
source

I think there is a shortcut to allow wcout to be handled wcout on Windows. Try adding this as the first line to your main :

 _setmode(_fileno(stdout), _O_U16TEXT); 

After that wcout << L" (2)!" << endl; wcout << L" (2)!" << endl; will work like a charm regardless of the current locale and single-byte encoding selected by the user (as it should be).

0
source

Source: https://habr.com/ru/post/1444143/


All Articles