#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <wchar.h>
#include <string.h>
#include <tchar.h>
ASCII字符集,多字节 或者 双子符字符集
// int main()
// {
// int i = 0;
// char c = 'A'; //char ,ASCII,是1个字节
// char str[] = "中国"; //这种保存中文的方法是没有Unicode之前的老方法
// //容易出错
// i = strlen(str);
// printf("长度:%d\n",i);
// printf("%s",str);
// printf("%c\n",c);
// system("pause");
// return 0;
// }
//int main()
//{
// int i = 0;
// wchar_t c = L'中'; //宽字符,Unicode字符,两个字节
// wchar_t str[] = L"中国"; //宽字符串
//
//
// setlocale(LC_ALL,"chs");//设置中文语言
// wprintf(L"%lc\n",c); //printf不能显示宽字符
// //在字符或字符串常量之前使用L前缀来指定宽字符类型的常量。
// i = wcslen(str);
// wprintf(L"长度:%d\n",i);
// wprintf(L"%ls\n",str);
// system("pause");
// return 0;
//}
//真正做Windows程序的时候都是用通用的类型和函数
int main()
{
//TCHAR 会自动的根据字符集而选择类型
TCHAR str[] = _T("中国");
//setlocale(LC_ALL,"chs"); //设置本地区域语言,如果默认为ASCII 则不需要此设置
_tprintf("%s\n",str);
system("pause");
return 0;
}
#include <Windows.h>
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
//ASCII
MessageBoxA(NULL,"hello 中国","标题:ASCII",MB_YESNO | MB_ICONINFORMATION);
//Unicode
MessageBoxW(NULL,L"hello 中国",L"标题:Unicode",MB_YESNO | MB_ICONHAND);
//common,最好用第三个
MessageBox(NULL,TEXT("hello 中国"),TEXT("标题:common"),MB_OK | MB_ICONEXCLAMATION);
return 0;
}
//#ifdef UNICODE
//#define MessageBox MessageBoxW
//#else
//#define MessageBox MessageBoxA
//#endif // !UNICODE
一:Unicode简介
1.两种字符集 ANSII Unicode(宽字符)
2.两种字符类型 char wchar_t
CHAR WCHAR
3.函数的两种版本 printf wprintf
Strlrn wcslen
MessageBoxA MessageBosW
4.通用版本 _tcslen
MessageBox
TCHAR
宏: TEXT,_TEXT,__T,_T
二:设计指南
1. ASCII版本
CHAR PCHAR ASCII字符串(没有L)
2. Unicode版本
WCHAR PWCHAR 宽字符串(带L)
3. 通用版本
TCHAR PTCHAR TEXT(宏)