C++中TCHAR数组(wchar_t*)和char数组相关函数的对应关系_C/C++_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > C/C++ > C++中TCHAR数组(wchar_t*)和char数组相关函数的对应关系

C++中TCHAR数组(wchar_t*)和char数组相关函数的对应关系

 2016/5/12 5:33:18  aigo  程序员俱乐部  我要评论(0)
  • 摘要:MSDN文档:strlen,wcslen,_mbslen,_mbslen_l,_mbstrlen,_mbstrlen_lhttps://msdn.microsoft.com/en-us/library/78zh94ax.aspxstrcmp,wcscmp,_mbscmphttps://msdn.microsoft.com/en-us/library/e0z9k731.aspxstrchr,wcschr,_mbschr,_mbschr_lhttps://msdn.microsoft.com/en
  • 标签:关系 函数 c++ 数组

MSDN文档:

strlen, wcslen, _mbslen, _mbslen_l, _mbstrlen, _mbstrlen_l

https://msdn.microsoft.com/en-us/library/78zh94ax.aspx

strcmp, wcscmp, _mbscmp

https://msdn.microsoft.com/en-us/library/e0z9k731.aspx

strchr, wcschr, _mbschr, _mbschr_l

https://msdn.microsoft.com/en-us/library/b34ccac3.aspx

?

?

char*函数与THCAR*(wchar_t*)函数对应关系是:

strlen -》?wcslen

strcpy -》?wcscpy

strcmp -》wcscmp

strchr -》 wcschr

?

代码示例:

class="cpp">// crt_strlen.c
// Determine the length of a string. For the multi-byte character
// example to work correctly, the Japanese language support for
// non-Unicode programs must be enabled by the operating system.


#include <string.h>
#include <locale.h>

int main()
{
   char* str1 = "Count.";
   wchar_t* wstr1 = L"Count.";
   char * mbstr1;
   char * locale_string;

   // strlen gives the length of single-byte character string
   printf("Length of '%s' : %d\n", str1, strlen(str1) );

   // wstrlen gives the length of a wide character string
   wprintf(L"Length of '%s' : %d\n", wstr1, wcslen(wstr1) );

   // A multibyte string: [A] [B] [C] [katakana A] [D] [\0]
   // in Code Page 932. For this example to work correctly,
   // the Japanese language support must be enabled by the
   // operating system.
   mbstr1 = "ABC" "\x83\x40" "D";

   locale_string = setlocale(LC_CTYPE, "Japanese_Japan");

   if (locale_string == NULL)
   {
      printf("Japanese locale not enabled. Exiting.\n");
      exit(1);
   }
   else
   {
      printf("Locale set to %s\n", locale_string);
   }

   // _mbslen will recognize the Japanese multibyte character if the
   // current locale used by the operating system is Japanese
   printf("Length of '%s' : %d\n", mbstr1, _mbslen(mbstr1) );

   // _mbstrlen will recognize the Japanese multibyte character
   // since the CRT locale is set to Japanese even if the OS locale
   // isnot. 
   printf("Length of '%s' : %d\n", mbstr1, _mbstrlen(mbstr1) );
   printf("Bytes in '%s' : %d\n", mbstr1, strlen(mbstr1) );   

}

?

发表评论
用户名: 匿名