目录
1简介
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;
}
|
参考:
wchar 数据类型 谷歌

本博文详细解析了wchar_t字符类型的特点、作用及如何将其与其他字符类型进行转换,重点阐述了其在国际化程序开发中的重要性。通过实例代码展示了如何使用wchar_t类型进行宽字符操作,并提供了将char转换为wchar_t的具体方法。
830

被折叠的 条评论
为什么被折叠?



