You are here:

C++/Unicode character print using C or C++

Advertisement


Question
Dear Titus,

I want to print some unicode character(of Hindi language) as output. what are the procedure I have to follow? Is there any library function or header file for Unicode character printing. Please help me. if possible please give some example. Thank you in advance.  

Answer
Dear Nava:

This is really not my expertise, but I will try to help as much as I can.

The first thing you will have to do is set your machine to be able to type Hindi fonts.  You may already know this, but I am not sure from the question whether you do or not.  I do not have access to a system that is set up to type Hindi fonts.  Even so, if you know the two byte code (short) for the fonts you want to represent you may not have to have Language support for Hindi fonts.  But you will have to use the exact code instead of the actual font (in a string) in a string of such codes.  The next thing you need is some Hindi fonts.  I went on fontfreak.com and I found one Hindi font you can download for free.  Then you will have to set the font in your application.  Below is a code sample for setting font for a CEditView in Visual C++:

http://www.functionx.com/visualc/applications/notes.htm

void CNotesView::OnInitialUpdate()
{
  CEditView::OnInitialUpdate();
  
  // TODO: Add your specialized code here and/or call the base class
  CEdit &curEditor = GetEditCtrl();
  CFont *SimpleFont = new CFont;

  SimpleFont->CreatePointFont(120, "Times New Roman");
  curEditor.SetFont(SimpleFont);
}

Finally you will declare the character strings in the code.  Unicode characters are two bytes long each not the one byte characters of the ASCI character string.  Below, is a coding sample that will help you set that up in the code:

http://www.flipcode.com/archives/Advanced_String_Techniques_in_C-Part_I_Unicode.

#define _UNICODE   // Tell C we're using Unicode, notice the _
#include <tchar.h>   // Include Unicode support functions
#include <stdlib.h>
#include <string.h>
typedef unsigned short wchar_t;
#define UNICODE          // No underscore this time
#include <windows.h>
wchar_t mystring[] = _TEXT("flipcode");

I hope this helps you.  I tried to cover all bases.  

Also, you can create your own characters.  You will find the format of a font file at http://support.microsoft.com/kb/65123.  You can also use software applications to help you create your fonts http://desktoppub.about.com/gi/dynamic/offsite.htm?zi=1/XJ/Ya&sdn=desktoppub&zu=.  First you get bitmap images of each character, then you put each on into the software to represent each character.  The example I saw was mapping English characters, however.

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Titus B. Ledbetter, Jr.

Expertise

C , MFC, Object Oriented, Artificial Intelligence

Experience

I have over ten years experience in the field of Computer Science, five years experience developing C/C++. I recently wrote a chess program using Object Oriented, C++, MFC.

Education/Credentials
Master's Degree Computer Science from Johns Hopkins

©2016 About.com. All rights reserved.