멀티바이트를 유니코드 문자열로 혹은 역으로 변환하는 함수 C/C++, Debugging

mbstowcs() : 멀티바이트 스트링을 와이드캐릭터 스트링으로 변경

wcstombs() : 와이드캐릭터 스트링을 멀티바이트 스트링으로 변경

 

 

 #ifdef WIN32
  #pragma warning(disable:4786)
#endif
#include <iostream>
using namespace std;

void string2wstring(wstring &dest,const string &src)
{
     dest.resize(src.size());
     for ( unsigned int  i=0; i<src.size(); i++)
        dest[i] = static_cast<unsigned char>(src[i]);
}

void wstring2string(string &dest,const wstring &src)
{
     dest.resize(src.size());
     for (unsigned int i=0; i<src.size(); i++)
         dest[i] = src[i] < 256 ? src[i] : ' ';
}

int main ( int argc, char** argv )
{
  string str = "한글 English";
  wstring wstr;

  string2wstring( wstr, str );
  wcout << L"[2Byte] " << wstr.c_str() << endl;
  wstring2string ( str, wstr );
  cout << "[1Byte] " << str.c_str() << endl;
  return 0;
}


트랙백

이 글과 관련된 글 쓰기 (트랙백 보내기)
TrackbackURL : http://includes.egloos.com/tb/1504681 [도움말]