6

I know a simple way for correct displaying of localized chars on Cmd.exe. But how can I do 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;
}
Ry-
  • 218,210
  • 55
  • 464
  • 476
Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182

2 Answers2

0

What is the output? Is your font supporting those glyphs?

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

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

You could also try to redirect output from powershell to a file and check that. If the file is correct, you have a console-font not supporting your characters.

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

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

rhavin
  • 1,512
  • 1
  • 12
  • 33
0

I think that's there's a shortcut to enable proper wcout handling in Windows. Try to add that as a first line to your main:

_setmode(_fileno(stdout), _O_U16TEXT);

After that wcout << L"Привет мир (2)!" << endl; will work like a charm independently of current locale and single-byte encoding chosen by user (as it should).

ForNeVeR
  • 6,726
  • 5
  • 24
  • 43