zoukankan      html  css  js  c++  java
  • TCHAR和CHAR类型的互转

    http://blog.csdn.net/ahjxly/article/details/8494217

    http://blog.csdn.net/b_h_l/article/details/7581519

    http://blog.chinaunix.net/uid-339069-id-3402668.html

    没有定义UNICODE,所以它里面的字符串就是简单用" "就行了,创建工程的时候包含了UNICODE定义,就必须对TCHAR和char进行转换。

    void TcharToChar(const TCHAR * tchar, char * _char)
    {
        int iLength;
        //获取字节长度   
        iLength = WideCharToMultiByte(CP_ACP, 0, tchar, -1, NULL, 0, NULL, NULL);
        //将tchar值赋给_char    
        WideCharToMultiByte(CP_ACP, 0, tchar, -1, _char, iLength, NULL, NULL);
    }
    
    void CharToTchar(const char * _char, TCHAR * tchar)
    {
        int iLength;
        iLength = MultiByteToWideChar(CP_ACP, 0, _char, strlen(_char) + 1, NULL, 0);
        MultiByteToWideChar(CP_ACP, 0, _char, strlen(_char) + 1, tchar, iLength);
    }

    表明 TCHAR 与 WCHAR 属同一类型
    char szA[100];                    // ANSI string buffer
    WCHAR szW[100];            // Unicode string buffer
    // Normal sprintf:all strings are ANSI
    sprintf(szA, "%s","ANSI Str");
    // Converts Unicode string to ANSI
    sprintf(szA,"%S",L"Unicode Str");
    // Normal swprintf:all strings are Unicode
    swprintf(szW,L"%s",L"Unicode Str");
    // Converts ANSI string to Unicode
    swprintf(szW,L"%S", "ANSI Str");
    注意:大写S 和小写s 的使用

     
  • 相关阅读:
    ubuntu文件夹建立软链接方法
    编译android内核和文件系统,已经安装jdk,提示build/core/config.mk:268: *** Error: could not find jdk tools.jar
    ubuntu12.04配置NFS服务详解
    解决ubuntu10.04不能上网
    GC
    IO
    HashMap
    JavaBean的介绍
    SSO二 之CAS
    SSO一 之介绍
  • 原文地址:https://www.cnblogs.com/yuguangyuan/p/5955959.html
Copyright © 2011-2022 走看看