Author Topic: [C++] outputting unicode strings...  (Read 7569 times)

0 Members and 1 Guest are viewing this topic.

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1390
  • Karma: 84
    • View Profile
[C++] outputting unicode strings...
« on: June 13, 2011 »

I currently have the need to output some unicode characters into the console window.
I wish to output some braille characters like shown  here...
http://tlt.its.psu.edu/suggestions/international/bylanguage/braillechart.html

These will be dithering patterns in a crude image to text program.
Please help if you can.

Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [C++] outputting unicode strings...
« Reply #1 on: June 13, 2011 »
Like this ?
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1390
  • Karma: 84
    • View Profile
Re: [C++] outputting unicode strings...
« Reply #2 on: June 13, 2011 »
I'm using GCC\Linux and it looks like that code may not be compatible.

Resulting debug:
Code: [Select]
C:\Users\ryan\Desktop\blarg_test\main.cpp||In function 'int main()':|
C:\Users\ryan\Desktop\blarg_test\main.cpp|8|error: 'WCHAR' was not declared in this scope|
C:\Users\ryan\Desktop\blarg_test\main.cpp|8|error: expected ';' before 'c'|
C:\Users\ryan\Desktop\blarg_test\main.cpp|9|error: 'c' was not declared in this scope|
||=== Build finished: 3 errors, 0 warnings ===|

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [C++] outputting unicode strings...
« Reply #3 on: June 14, 2011 »
Correct, that code is for Microsoft C runtime only.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [C++] outputting unicode strings...
« Reply #4 on: June 15, 2011 »
Code: [Select]
#include <stdio.h>
int main(void)
{
printf("%lc", 0x280F);
return 0;
}
Does this work?

Jim
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1390
  • Karma: 84
    • View Profile
Re: [C++] outputting unicode strings...
« Reply #5 on: June 15, 2011 »
Oddly enough I dont see any character printed from that code Jim.

I'm fairly sure Debian supports Unicode in the terminal but I see nothing printed out. It does not have any errors or exceptions when debugging either.  ???

I did try a few things before posting here but still came up empty handed.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [C++] outputting unicode strings...
« Reply #6 on: June 15, 2011 »
Yes, your terminal probably supports unicode via utf-8 encoding, but the question is if your C runtime can spit them out properly.

How about:

printf("\x28\x0F");
or
printf("\x0F\x28");

Jim

Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1390
  • Karma: 84
    • View Profile
Re: [C++] outputting unicode strings...
« Reply #7 on: June 15, 2011 »
That time I got something Jim.

The character (   was printed for both calls.

I did one character then called printf with the other.
You can see the output "((" then my command prompt returned.

Code: [Select]

#include <stdio.h>
int main(void)
{
     printf("\x28\x0F");
     printf("\x0F\x28");
     return 0;
}

« Last Edit: June 15, 2011 by Pixel_Outlaw »
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1390
  • Karma: 84
    • View Profile
Re: [C++] outputting unicode strings...
« Reply #8 on: June 20, 2011 »
Hmm I can output a block character from unicode directly with my compiler:

Code: [Select]
cout << "▒" << endl;

However I have a feeling that this is not portable nor standard usage...
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1390
  • Karma: 84
    • View Profile
Re: [C++] outputting unicode strings...
« Reply #10 on: June 21, 2011 »

Jim, thanks for the information.  Looks like I am running the correct kernel version. (2.6.32)

I've decided to just use standard cout calls with the braille character plopped directly into the editor.
I won't worry about a Windows port of my image viewer simply because most of the time Windows users use only the GUI.
Challenge Trophies Won: