Question

I have a cpp file that uses ibm cp437 and Visual C++ keeps reading it with windows-1252. How do I make Visual C++ use the right code page for the file?

Was it helpful?

Solution

Alright, I figured it out myself. For the curious, here is the answer:

  • Right click the file in the Solution Explorer.
  • Select "Open With..."
  • Choose "C++ Source Code Editor (with encoding)"
  • A new box appears to specify Encoding. Choose "OEM United States - Codepage 437"

Done.

OTHER TIPS

Unless you need the CP437 encoding, why don't you convert it to CP1252, UTF-8 or MS 'Unicode' (UCS-2)? Any reasonably capable editor should be able to do it.

VS2008 can do it - check out the Advanced Save option on the File menu.

Edit:

If you go to Source Control Explorer, right-click on the file, select 'Properties', you can set the encoding on the 'General' tab page. 'IBM437' is one of the choices.

I also encountered these errors in my environments. I think there's any easier way to change the default code pages.

In windows 10, you could go to "Settings" -> "Region" -> "Administrative" tab -> "Language for non-Unicode programs". Then you could choose the region you want.

In this way, all the codes read from Visual Studio would use the code page whatever you want.

For example, the default setting for me is Chinese (Traditional, Taiwan). The code page is 950. But the codes are using windows-1252, therefore, I change the region to English (United States).

That's it.

Hope the solution could help you.

Thanks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top