wchar_tはC/C++の文字タイプであり、拡張された記憶方式である
3567 ワード
wchar_tはC/C++の文字タイプで、拡張的な記憶方式で、wchar_tタイプは主に国際化プログラムの実装に用いられるが,uni符号化に等しくない.uni符号化文字は一般的にwchar_であるtタイプストレージ.
外国語名
wchar_t
に属する
C/C++の文字タイプ
クラス
拡張されたストレージ方式
概念的
8ビット文字タイプ
目次
1概要
2例えば
3 charをwchar_に変換t
1概要
charは8ビット文字タイプで、最大256文字しか含まれません.多くの外国語文字セットに含まれる文字数は256文字を超えており、char型は表すことができません.
wchar_tデータ型は一般に16ビットまたは32ビットであるが、異なるCまたはC++ライブラリには異なる規定があり、例えばGNU Libcがwchar_を規定するtは32ビット
[1],とにかくwchar_tが表す文字数はchar型をはるかに超えている.
標準C++のwprintf()関数とiostreamクラスライブラリのクラスとオブジェクトはwchar_を提供します.t幅文字タイプに関する操作.
2例えば
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
3 charをwchar_に変換t
TEXT()メソッドでcharをwchar_に変換できますt
例:wchar_t appName[5]=TEXT("test");
方法2:
1
2
3
4
5
6
7
8
参考資料
1. GNU Libc:Introduction to Extended Characters .
参照先:
wcharデータ型グーグル
外国語名
wchar_t
に属する
C/C++の文字タイプ
クラス
拡張されたストレージ方式
概念的
8ビット文字タイプ
目次
1概要
2例えば
3 charをwchar_に変換t
1概要
charは8ビット文字タイプで、最大256文字しか含まれません.多くの外国語文字セットに含まれる文字数は256文字を超えており、char型は表すことができません.
wchar_tデータ型は一般に16ビットまたは32ビットであるが、異なるCまたはC++ライブラリには異なる規定があり、例えばGNU Libcがwchar_を規定するtは32ビット
[1],とにかくwchar_tが表す文字数はchar型をはるかに超えている.
標準C++のwprintf()関数とiostreamクラスライブラリのクラスとオブジェクトはwchar_を提供します.t幅文字タイプに関する操作.
2例えば
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <locale>
#include <cstdlib>
usingnamespace std;
locale loc(
"chs"
);
//windows ok
// ubuntu ok
//locale loc("zh_CN.UTF-8");
// ubuntu :
//sudo locale-gen
int
main(){
wchar_t
wStr[]=L
" "
;
wcout.imbue(loc);
wcout<<wStr<<endl;
getchar
();
getchar
();
return0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
package
MyJava;
// demo
public
class
MyDemo{
public
static
void
main(Stringargs[]){
intnum =
300
;
System.out.println(
" :"
+num);
inta =
30
;
intb =
20
;
intc = a+b;
System.out.println(
"a+b="
+c);
}
}
3 charをwchar_に変換t
TEXT()メソッドでcharをwchar_に変換できますt
例:wchar_t appName[5]=TEXT("test");
方法2:
1
2
3
4
5
6
7
8
wchar_t
* c2w(
const
char
*str)
{
int
length =
strlen
(str)+1;
wchar_t
*t = (
wchar_t
*)
malloc
(
sizeof
(
wchar_t
)*length);
memset
(t,0,length*
sizeof
(
wchar_t
));
MultiByteToWideChar(CP_ACP,0,str,
strlen
(str),t,length);
return
t;
}
参考資料
1. GNU Libc:Introduction to Extended Characters .
参照先:
wcharデータ型グーグル