Ok, i will try...
[EDIT 31.01.2018] Update this:
Steps to do:1) Put the line
system("chcp 65001 > nul");
as first line in your main:
#include <stdio.h>
#include <windows.h>
int main()
{
system("chcp 65001 > nul"); // Important code line executed before any printf call
// your code here...
printf("На берегу пустынных волн\n"); // some Russian
printf("Я можу їсти скло, і воно мені не зашкодить\n"); // some Ukrainian
printf("Mohu jíst sklo, neublíží mi. \n"); // some Czech
printf("Môžem jesť sklo. Nezraní ma. \n"); // some Slovak
printf("Mogę jeść szkło i mi nie szkodzi. \n"); // some Polish
return 0;
}
2) Save as UTF-8 file. Do this by calling the following menu entries in codeblocks:
Edit->File encoding->UTF-8
Save the file:
File->Save file
every code file you use should be set to UTF-8 encoding
3) Compile and run. This will probably show gibberish (white squares) in the console... To change this you have to set the correct font:
3.1) After compiling and run the console will open (This black window)
3.2) In this window right click on the top left corner: A Menu will open. Select "Properties"
3.3) In the opening window select "Font" tab from the top
3.4) Select
Lucida Console in the Font list
3.5) Hit "OK"
now you should see all characters right.
Limitations: This limitations come from windows, not codeblocks:
1) You can only use "printf" "std::cout" will not work[EDIT:] You can use std::cout with this method. If it is not working you have to update your compiler, or use utf8 literals that are supported by c++11
2) You have to set the console font on every machine you run this code, or you will always get this gibberish
Advantages with this approach:1) Your code runs on linux windows and mac (if you remove the system line and replace it with the appropriate line)
2) Your code runs with any utf-8 supported language (as far as the font supports it, you don't have to switch encoding/codepage or have some mixed handling like utf-16)
3) You have not to deal with wide character strings like "wchar_t" and "wcout"
Disadvantages:1) See Limitations
2) With this approach you are using UTF-8 encoded strings[1][2]. String functions don't work as expected [3]:
for example this
printf("string length: %i (24 expected)\n", strlen("На берегу пустынных волн"));
prints this:
string length: 45 (24 expected)
and for example:
char test[25] = "На берегу пустынных волн";
wont compile, because the string is actually 46 characters long
but this will work:
char test[] = "На берегу пустынных волн";
But this is all to complicated... Is there not a more easy way to do?Yes there is a more easy way to do. You use the default windows codepage from your system. I have never used this because i don't want to handle windows code pages because this is different for every language out there. If you are Korean you have to use a other code page then from Japan, or from Russia. There are for sure other websites out there that can explain this to you, but i won't
I use some asian language and done all your steps but i still see only small white rectangles instead of the right symbols?You have hit the limit of the
Lucida Console font. You have to change to some other font like "currier new". How you do this? Duckduckgo and "lucida console japanese" is your friend
hope this helps...
[1]
https://en.wikipedia.org/wiki/UTF-8[2]
http://utf8everywhere.org/[3]
http://www.zedwood.com/article/cpp-utf8-strlen-function