乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      CString、TCHAR*、char*轉(zhuǎn)換

       刀下巴 2015-02-24
      char*、TCHAR*轉(zhuǎn)換CString 
      CString str(****) 
      下面詳細(xì)寫一下其它轉(zhuǎn)換 
      ////////////////////////////// 
      /* 
      *********************************************************************** 
      * 函數(shù): TransCStringToTCHAR 
      * 描述:將CString 轉(zhuǎn)換為 TCHAR* 
      * 日期:
      *********************************************************************** 
      */ 
      TCHAR* CPublic::CString2TCHAR(CString &str) 
      int iLen = str.GetLength(); 
      TCHAR* szRs = new TCHAR[iLen]; 
      lstrcpy(szRs, str.GetBuffer(iLen)); 
      str.ReleaseBuffer(); 
      return szRs; 
      /* 
      *********************************************************************** 
      * 函數(shù): TCHAR2Char 
      * 描述:將TCHAR* 轉(zhuǎn)換為 char* 
      * 日期:


      *********************************************************************** 
      */ 
      char* TCHAR2char(TCHAR* tchStr) 
      int iLen = 2*wcslen(tchStr);//CString,TCHAR漢字算一個(gè)字符,因此不用普通計(jì)算長(zhǎng)度 
      char* chRtn = new char[iLen+1] 
      wcstombs(chRtn,tchStr,iLen+1);//轉(zhuǎn)換成功返回為非負(fù)值 
      return chRtn; 
      /*

      *********************************************************************** 
      * 函數(shù): char2tchar
      * 描述:將 char* 轉(zhuǎn)換為 TCHAR*
      * 日期:


      *********************************************************************** 
      */ 
      TCHAR *char2tchar(char *str)
      {
      int iLen = strlen(str);
      TCHAR *chRtn = new TCHAR[iLen+1];
      mbstowcs(chRtn, str, iLen+1);
      return chRtn;
      }
      /* 
      *********************************************************************** 
      * 函數(shù): CString2char 
      * 描述:將CString轉(zhuǎn)換為 char* 
      * 日期:
      *********************************************************************** 
      */ 
      char* CPublic::CString2char(CString &str) 
      int len = str.GetLength(); 
      char* chRtn = (char*)malloc((len*2+1)*sizeof(char));//CString的長(zhǎng)度中漢字算一個(gè)長(zhǎng)度 
      memset(chRtn, 0, 2*len+1); 
      USES_CONVERSION; 
      strcpy((LPSTR)chRtn,OLE2A(str.LockBuffer())); 
      return chRtn; 
      //參考 
      /////////////////////// 
      //Pocket PC上的UNICODE和ANSI字符串 
      //By Vassili Philippov, September 26, 2001. 
      //楊方思歧 譯 
      //////////////////////// 
      /* 
      *********************************************************************** 
      * 函 數(shù) 名:GetAnsiString 
      * 描 述:將CString(unicode)轉(zhuǎn)換為char*(ANSI) 
      * 參 數(shù):CString &s 要轉(zhuǎn)換的CString 
      * 返 回 值:返回轉(zhuǎn)換結(jié)果 
      * 創(chuàng)建日期:
      * 最后修改:
      *********************************************************************** 
      */ 
      char* GetAnsiString(const CString &s) 
      int nSize = 2*s.GetLength(); 
      char *pAnsiString = new char[nSize+1]; 
      wcstombs(pAnsiString, s, nSize+1); 
      return pAnsiString; 
      //////////////////////////////////////////////////////////////////////////////////////////////

      WideCharToMultiByte和MultiByteToWideChar函數(shù)的用法
      支持Unicode編碼,需要多字節(jié)與寬字節(jié)之間的相互轉(zhuǎn)換
      WideCharToMultiByte的代碼頁用來標(biāo)記與新轉(zhuǎn)換的字符串相關(guān)的代碼頁。
      MultiByteToWideChar的代碼頁用來標(biāo)記與一個(gè)多字節(jié)字符串相關(guān)的代碼頁。
      常用的代碼頁由CP_ACP和CP_UTF8兩個(gè)。
      使用CP_ACP代碼頁就實(shí)現(xiàn)了ANSI與Unicode之間的轉(zhuǎn)換。
      使用CP_UTF8代碼頁就實(shí)現(xiàn)了UTF-8與Unicode之間的轉(zhuǎn)換。
      wstring AnsiToUnicode(( const string& str )
      {
      int len = 0;
      len = str.length();
      int unicodeLen = ::MultiByteToWideChar( CP_ACP, 0, str.c_str(),-1,NULL,0 ); 
      wchar_t * pUnicode; 
      pUnicode = new wchar_t[unicodeLen+1]; 
      memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t)); 
      ::MultiByteToWideChar( CP_ACP,0, str.c_str(),-1, (LPWSTR)pUnicode, unicodeLen ); 
      wstring rt; 
      rt = ( wchar_t* )pUnicode;
      delete pUnicode; 
      return rt; 
      }
      string UnicodeToAnsi( const wstring& str )
      {
      char* pElementText;
      int iTextLen;
      // wide char to multi char
      iTextLen = WideCharToMultiByte( CP_ACP, 0, str.c_str(), -1, NULL, 0, NULL, NULL );
      pElementText = new char[iTextLen + 1];
      memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) );
      ::WideCharToMultiByte( CP_ACP, 0, str.c_str(), -1, pElementText,iTextLen,NULL,NULL );
      string strText;
      strText = pElementText;
      delete[] pElementText;
      return strText;
      }
      wstring UTF8ToUnicode(( const string& str )
      {
      int len = 0;
      len = str.length();
      int unicodeLen = ::MultiByteToWideChar( CP_UTF8, 0, str.c_str(),-1,NULL,0 ); 
      wchar_t * pUnicode; 
      pUnicode = new wchar_t[unicodeLen+1]; 
      memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t)); 
      ::MultiByteToWideChar( CP_UTF8,0, str.c_str(),-1, (LPWSTR)pUnicode, unicodeLen ); 
      wstring rt; 
      rt = ( wchar_t* )pUnicode;
      delete pUnicode; 
      return rt; 
      }
      string UnicodeToUTF8( const wstring& str )
      {
      char* pElementText;
      int iTextLen;
      // wide char to multi char
      iTextLen = WideCharToMultiByte( CP_UTF8, 0, str.c_str(), -1, NULL, 0, NULL, NULL );
      pElementText = new char[iTextLen + 1];
      memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) );
      ::WideCharToMultiByte( CP_UTF8, 0, str.c_str(), -1, pElementText,iTextLen,NULL,NULL );
      string strText;
      strText = pElementText;
      delete[] pElementText;
      return strText;
      }

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多