문자열변환2

송정헌 2010-01-18 11:47:30 주소복사
조회 28 스크랩 0

char *, wchar_t *, _bstr_t, CComBSTR, CString, basic_string, System.String 변환

char *

char *orig = "Hello, World!";

size_t origsize = strlen(orig) + 1; // wchar_t *

const size_t newsize = 100;

size_t convertedChars = 0;

wchar_t wcstring[newsize];

mbstowcs_s(&convertedChars, wcstring, origsize, orig, _TRUNCATE);

wcscat_s(wcstring, L" (wchar_t *)");

_bstr_t bstrt(orig); // _bstr_t

bstr += " (_bstr_t)";

CComBSTR ccombstr(orig); // CComBSTR

if(ccombstr.Append(L"(CComBSTR)") == S_OK) CW2A printstr(ccombstr);

CString cstring(orig); // CString

cstring += " (CString)";

string basicstring(orig); // basic_string

basicstring += " (basic_string)";

String ^systemstring = gcnew String(orig); // System.String

systemstring += " (System::String)";

delete systemstring;

wchar_t *

wchar_t *orig = L"Hello, World!";

size_t origsize = wcslen(orig) + 1; // char *

const size_t newsize = 100;

size_t convertedChars = 0;

char nstring[newsize];

wcstombs_s(&convertedChars, nstring, origsize, orig, _TRUNCATE);

strcat_s(nstring, " (char *)");

_bstr_t bstrt(orig); // _bstr_t

bstrt += " (_bstr_t)";

CComBSTR ccombstr(orig); // CComBSTR

if(ccombstr.Append(L" (CComBSTR)") == S_OK) CW2A printstr(ccombstr);

CString cstring(orig); // CString

cstring += " (CString)";

wstring basicstring(orig); // basic_string

basicstring += L" (basic_string)";

String ^systemstring = gcnew String(orig); // System.String

systemstring += " (System::String)";

delete systemstring;

_bstr_t

BSTR을 캡슐화하는 COM 지원 클래스 (comutil.h, comsuppw.lib 또는 comsuppwd.lib)

_bstr_t orig("Hello, World!");

const size_t newsize = 100; // char *

char nstring[newsize];

strcpy_s(nstring, (char *)orig);

strcat_s(nstring, " (char *)");

wchar_t wcstring[newsize]; // wchar_t *

wcscpy_s(wcstring, (wchar_t *)orig);

wcscat_s(wcstring, L" (wchar_t *)");

CComBSTR ccombstr((char *)orig); // CComBSTR

if(ccombstr.Append(L" (CComBSTR)") == S_OK) CW2A printstr(ccombstr);

CString cstring((char *)orig); // CString

cstring += " (CString)";

string basicstring((char *)orig); // basic_string

basicstring += " (basic_string)";

String ^systemstring = gcnew String((char *)orig); // System.String

systemstring += " (System::String)";

delete systemstring;

CComBSTR ATL의 BSTR wrapper 클래스 (atlbase.h)

CComBSTR orig("Hello, World!");

CW2A printstr(orig);

const size_t newsize = 100; // char *

char nstring[newsize];

CW2A tmpstr1(orig);

strcpy_s(nstring, tmpstr1);

strcat_s(nstring, " (char *)");

wchar_t wcstring[newsize]; // wchar_t *

wcscpy_s(wcstring, orig);

wcscat_s(wcstring, L" (wchar_t *)");

_bstr_t bstrt(orig); // _bstr_t

bstrt += " (_bstr_t)";

CString cstring(orig); // CString

cstring += " (CString)";

wstring basicstring(orig); // basic_string

basicstring += L" (basic_string)";

String ^systemstring = gcnew String(orig); // System.String

systemstring += " (System::String)";

delete systemstring;

CString ATL/MFC의 템플릿 클래스인 CStringT의 기본 구현 클래스.

CString orig("Hello, World!");

const size_t newsize = 100; // char *

char nstring[newsize];

strcpy_s(nstring, orig);

strcat_s(nstring, " (char *)");

// wchar_t * (이 작업을 하려면 먼저 char *로 바꿔야 한다)

size_t origsize = strlen(orig) + 1;

size_t convertedChars = 0;

wchar_t wcstring[newsize];

mbstowcs_s(&convertedChars, wcstring, origsize, orig, _TRUNCATE);

wcscat_s(wcstring, L" (wchar_t *)");

_bstr_t bstrt(orig); // _bstr_t

bstrt += " (_bstr_t)";

CComBSTR ccombstr(orig); // CComBSTR

if(ccombstr.Append(L" (CComBSTR)") == S_OK) CW2A printstr(ccombstr);

string basicstring(orig); // basic_string

basicstring += " (basic_string)";

String ^systemstring = gcnew String(orig); // System.String

systemstring += " (System::String)";

delete systemstring;

basic_string STL 클래스 (<string>)

string orig("Hello, World!");

const size_t newsize = 100; // char *

char nstring[newsize];

strcpy_s(nstring, orig.c_str());

strcat_s(nstring, " (char *)");

// wchar_t * (이 작업을 하려면 먼저 char *로 바꿔야 한다)

size_t origsize = strlen(orig.c_str()) + 1;

size_t convertedChars = 0;

wchar_t wcstring[newsize];

mbstowcs_s(&convertedChars, wcstring, origsize, orig.c_str(), _TRUNCATE);

wcscat_s(wcstring, L" (wchar_t *)");

_bstr_t bstrt(orig.c_str()); // _bstr_t

bstrt += "(_bstr_t)";

CComBSTR ccombstr(orig.c_str()); // CComBSTR

if(ccombstr.Append(L" (CComBSTR)") == S_OK) CW2A printstr(ccombstr);

Cstring cstring(orig.c_str()); // CString

cstring += " (CString)";

String ^systemstring = gcnew String(orig.c_str()); // System.String

systemstring += " (System::String)";

delete systemstring;

System.String .NET 프레임워크 클래스 (mscorlib)

String ^orig = gcnew String("Hello, World!");

pin_ptr<const wchar_t> wch = PtrToStringChars(orig);

size_t origsize = wcslen(wch) + 1; // char *

const size_t newsize = 100;

size_t convertedChars = 0;

char nstring[newsize];

wcstombs_s(&convertedChars, nstring, origsize, wch, _TRUNCATE);

strcat_s(nstring, " (char *)");

wchar_t wcstring[newsize]; // wchar_t *

wcscpy_s(wcstring, wch);

wcscat_s(wcstring, L" (wchar_t *)");

_bstr_t bstrt(wch); // _bstr_t

bstrt += " (_bstr_t)";

CComBSTR ccombstr(wch); // CComBSTR

if(ccombstr.Append(L" (CComBSTR)") == S_OK) CW2A printstr(ccombstr);

CString cstring(wch); // CString

cstring += " (CString)";

wstring basicstring(wch); // basic_string

basicstring += L" (basic_string)";

delete orig;

반응형

+ Recent posts