Skip to content

Instantly share code, notes, and snippets.

@1000copy
Created August 1, 2022 06:09
Show Gist options
  • Save 1000copy/41d5bb699454da4d2b8ca4d5c7039053 to your computer and use it in GitHub Desktop.
Save 1000copy/41d5bb699454da4d2b8ca4d5c7039053 to your computer and use it in GitHub Desktop.
chapter02-i18n.cpp
#include <iostream>
#include <assert.h>
#include <tchar.h>
int main(){
//single byte
const char* str1 = "hello";
assert(strlen(str1) == 5);
// error for double byte
const char* str2 = "你好";
assert(strlen(str2) == 4);
// double byte
const wchar_t* str3 = L"你好";
assert(wcslen(str3) == 2);
// general for double and single byte
const TCHAR* str4 = _TEXT("你好hello");
assert(_tcslen(str4) == 7);
}
@1000copy
Copy link
Author

1000copy commented Aug 1, 2022

如果你如我一样,懒得深究背后的MACRO定义,内存布局,大头小头之类的‘懒惰’程序员,只要这样就可以国际化了。

本来这样写的:

static char * szYes = "Yes";

对照编写即可

  static TCHAR * szYes = TEXT ("Yes") ;

格式化字符也一样 | static TCHAR * szFormat = TEXT ("%-13s %3d");

字符串操作函数,比如

从strlen ,改成_tcslen
strcat改成_tcscat

以此办理。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment