1 Replies - 1551 Views - Last Post: 16 November 2011 - 01:36 PM Rate Topic: -----

#1 Invisibledeath  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 79
  • Joined: 13-March 10

How can I display unicode characters in C++?

Posted 16 November 2011 - 01:12 PM

Hello I've talked with my IT teacher, so she wanted to test my programming skills and sent me some exercises and I need to write them in my native language, however as far as I remember I always programmed using ASCII characters and cout. How can I display unicode characters?
Here's my code. setmode displays scope errors for me. I program in CODE::BLOCKS IDE by the way.
#include <fcntl.h>
#include <io.h>
#include<iostream>

using namespace std;


bool ArBusTrikampis(int a, int b, int c);

int main(int argc, char* argv[])
{
    _setmode(_fileno(stdout), _O_U16TEXT);

    int a, b, c;

   cout<<"\t\tAr galima sudaryti trikampį?\n";

   cout<<"Įveskite 1-ąjį skačių: ";
   cin>>a;

   cout<<"\nĮveskite 2-ąjį skaičių: ";
   cin>>b;

   cout<<"\nĮveskite 3-ąjį skaičių: ";
   cin>>c;

   if(ArBusTrikampis(a,b,c))
   cout<<"Trikampį įmanoma sudaryti.\n";
   else
   cout<<"Trikampio neįmanoma sudaryti.\n";

   return 0;
}

bool ArBusTrikampis(int a, int b, int c)
{
   if(a + b > c && a + c > b && b + c > a)
      return true;
   else
      return false;
}




Here are the errors

xxxx\ArGalimaSudarytiTrikampi\main.cpp||In function 'int main(int, char**)':|
xxxx\ArGalimaSudarytiTrikampi\main.cpp|12|error: 'stdout' was not declared in this scope|
xxxx\ArGalimaSudarytiTrikampi\main.cpp|12|error: '_fileno' was not declared in this scope|
xxxx\ArGalimaSudarytiTrikampi\main.cpp|12|error: '_O_U16TEXT' was not declared in this scope|
||=== Build finished: 3 errors, 0 warnings ===|




Is This A Good Question/Topic? 0
  • +

Replies To: How can I display unicode characters in C++?

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: How can I display unicode characters in C++?

Posted 16 November 2011 - 01:36 PM

These functions are Microsoft specific functions and are probably not available with your compiler.

To print Unicode characters you probably should be using wide versions of cin, cout and the wide characters. See this link for: Tips on using Unicode. And you may also need to change your locale.

Edit: And you may want to check out the Boost Locale libraries.

Jim

This post has been edited by jimblumberg: 16 November 2011 - 01:38 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1