C ++ string / char和口音 [英] C++ string/char and accents

查看:134
本文介绍了C ++ string / char和口音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C ++中编写一个文本编写器,我将使用一个短语字符串,并为每个char值显示适当的位图字体。

I'm writing a text writer in C++, which I'll have a string of a phrase and display the appropriate bitmap font for each char value.

现在,它正在为普通人物工作,但我得到的口音和其他字符,如À,Á,Â等古怪的值

For now, it's working for the regular characters, but I'm getting weird values for accents and other characters such as À, Á, Â, Ã, etc

这样做:

int charToPrint = 'a';
//use this value to figure which bitmap font to display

位图字体这些字符,但在这行我没有得到我应该得到的值,例如:195为Ã,199为Ç等...

The bitmap font does have these characters, but on this line I'm not getting the values I'm supposed to get, such as: 195 for Ã, 199 for Ç, etc...

我尝试将项目的字符集从多字节更改为Unicode,但我不认为这是char-> int转换...

I tried changing my project's character set from Multi Byte to Unicode, but I don't think that does anything for the char->int conversion...

如何使用chars进行此转换?

How can I get this conversion with chars?

编辑: Studio 2012,Windows 7,它是一个带有位图字体的OpenGL应用程序。
我根据 char 值映射每个字符的位置/宽度/高度,因此字符 a 位于我的位图的位置97

I'm using Visual Studio 2012, Windows 7, and it's an OpenGL application with a bitmap font. I've mapped the positions/width/height of each character, according to it's char value, so the character a is at the position 97 of my bitmap font (plus width accounted for).

要绘制,我只需要根据字符代码来确定位置。

To draw, I just need to figure the position based on the char code.

我有一个短语的字符串,我要显示,我循环通过每个字符,计算charCode,并调用我的绘制函数。

I have a string of a phrase I want to display, and I loop through each character, figure the charCode, and call my draw function.

带有重音的字符,我得到负值,所以我的绘制函数不做任何事情(例如对于Ç没有位置-30)。
我需要计算如何正确得到这些值并发送到绘制函数。

For these characters with accents, I'm getting negative values, so my draw function doesn't do anything (there's no position -30 for Ç for example). I need to figure how to get these values properly and send to the draw function.

推荐答案

Unicode ,这是2013年已经:) 绝对最低限度每个软件开发人员绝对,积极地必须了解Unicode和字符集

Use Unicode, it is year 2013 already :) The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets

您将使用 wchar_t 作为类型和 UTF-16 / UTF-32 编码。这将使你的代码不仅支持不规则的字符,但更多的不规则的字符:)(没有这样的东西作为常规字符)。

You will use wchar_t as a type and UTF-16 / UTF-32 encoding. That will make your code supporting not only "irregular" characters but many more "irregular" characters :) (there is no such a thing as regular characters).

Example

wchar_t c = L'Á';
printf("char: %lc encoding: %d\n", c, c);

c = 0xc1; 
printf("char: %lc encoding: %d\n", c, c);

输出

char: Á encoding: 193
char: Á encoding: 193

这篇关于C ++ string / char和口音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆