program code in c++ to print unicode urdu characters

I want help to have a program to print all urdu or any other language(xcept english) characters(unicode) on console screen in c++..deadly need help
You need a unicode library to do that. Start here and pick one that suits you:
http://unicodebook.readthedocs.org/en/latest/libraries.html
Depends on the console.
If your console supports Unicode, as Linux console does, then there is nothing to do:

1
2
3
4
5
#include <iostream>
int main()
{
    std::cout << "میں اردو نہیں بولتا\n";
}

live demo: http://coliru.stacked-crooked.com/a/c92386ba87e53234

The standard C++ way that would work even if the console does not support Unicode would require a locale:

1
2
3
4
5
6
7
8
9
#include <iostream>
#include <locale>
#include <clocale>
int main()
{
    std::wcout.imbue(std::locale("en_US.utf8")); // any Unicode locale works
    std::setlocale(LC_ALL, "en_US.utf8"); // extra setup to satisfy C I/O subsystem
    std::wcout << L"میں اردو نہیں بولتا\n";
}


But if you're using the Windows console, it is slightly more complicated: Windows does not support Unicode except through proprietary WinAPI functions, and in fact does not support any multibyte locales. There are several ways to do that that you should find by a web search. The simplest is probably to use wide strings and set standard output to _O_WTEXT
1
2
3
4
5
6
7
8
#include <iostream>
#include <io.h> 
#include <fcntl.h>
int main()
{
	_setmode(_fileno(stdout), _O_WTEXT);
	std::wcout << L"میں اردو نہیں بولتا\n";
}

that makes it print میں اردو نہیں بولتا , although if your console does not have a font that can show it, you may have to redirect the output to a file and load it in notepad to see the characters.
Last edited on
Topic archived. No new replies allowed.