question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code page seems to be broken

See original GitHub issue

I wrote a simple cpp code β€˜program.cpp’, encoding in utf8, for only printing a chinese string:

#include<iostream>
int main()
{
    std::cout << "ε“ˆε“ˆε“ˆε“ˆε“ˆε“ˆ" << std::endl;
    return 0;
}

But it actually printed a wrong string:

> g++ .\program.cpp
>  .\a.exe
鍝堝搱鍝堝搱鍝堝搱

cmd & powershell

The current code page of cmd or powerhsell is 936-gbk. But I can use chcp 65001 to solve this problem:

>a.exe
鍝堝搱鍝堝搱鍝堝搱

>type program.cpp
#include<iostream>
int main()
{
    std::cout << "鍝堝搱鍝堝搱鍝堝搱" << std::endl;
    return 0;
}
Active code page: 65001

>a.exe
ε“ˆε“ˆε“ˆε“ˆε“ˆε“ˆ

>type program.cpp
#include<iostream>
int main()
{
    std::cout << "ε“ˆε“ˆε“ˆε“ˆε“ˆε“ˆ" << std::endl;
    return 0;
}

pwsh

The current code page is 65001-utf8. I cannot get correct chinese strings printed, and chcp 65001 doesn’t work.

> .\a.exe
鍝堝搱鍝堝搱鍝堝搱
> cat .\program.cpp
#include<iostream>
int main()
{
    std::cout << "ε“ˆε“ˆε“ˆε“ˆε“ˆε“ˆ" << std::endl;
    return 0;
}
Active code page: 65001
> .\a.exe
鍝堝搱鍝堝搱鍝堝搱
> cat .\program.cpp
#include<iostream>
int main()
{
    std::cout << "ε“ˆε“ˆε“ˆε“ˆε“ˆε“ˆ" << std::endl;
    return 0;
}

Environment data

zh-cn win10.

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
DHowettcommented, Sep 4, 2020

(If your application requires a specific codepage to be active, it should set it itself. It is almost always incorrect to rely on the global state of the console, because it will rarely be what you want.)

0reactions
iSazonovcommented, Sep 5, 2020

If this c# program will automatically set the codepage itself, why it fails if global codepage is ascii?

Your program does not set a code page. https://stackoverflow.com/questions/45575863/how-to-print-utf-8-strings-to-stdcout-on-windows

<div>Stack Overflow</div><div>How to print UTF-8 strings to std::cout on Windows?</div><div>I'm writing a cross-platform application in C++. All strings are UTF-8-encoded internally. Consider the following simplified code:

#include <string> #include <iostream>

int main() { …</div>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Windows codepage is broken - character encoding
So it seems that my codepage became broken or something... I believe it should be Windows-1251 . But I don't know/remeber is there...
Read more >
What to Do When Your Website is Broken
In this this article, we will show you 7 general steps to fix your website, application, or code when it's broken.
Read more >
Website weirdly broken - html
Unfortunately, CodeAnywhere seems to have the same issue. Do you have an earlier version of the code that you can open inΒ ...
Read more >
We're sorry but this feature appears to be broken and ...
I just started to get this message this morning" We're sorry but this feature appears to be broken and needs to be repaired....
Read more >
My code is broken somewhere and I can't find the error.
Hello! I have run through the video multiple times checking for syntax and also downloaded the project files, which didn't help, however...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found