티스토리 뷰

'CString' to 'std::string':

CString cs("Hello");
std::string s((LPCTSTR)cs);


'std::string' to 'CString':

std::string s("Hello");
CString cs(s.c_str());



1. CString -> std::string

    CString str = "hello";
    std::string stdStr = str.GetBuffer(0);

2. std::string -> CString

    std::string stdStr = "hello";
    CString str  = stdStr.c_str();



How to: Convert Between Various String Types
http://msdn.microsoft.com/library/ms235631.aspx




CString Operations Relating to C-Style Strings
http://msdn.microsoft.com/en-us/library/awkwbzyc.aspx



CString -> WCHAR*

< Method 1 >

CString str("369048");

LPTSTR pstr = str.GetBuffer(str.GetLength());
LPWSTR pwstr = new WCHAR[7];

int len = MultiByteToWideChar(CP_ACP, 0, pstr, -1, NULL, NULL);
MultiByteToWideChar(CP_ACP, 0, pstr, -1, pwstr, len);

delete[] pwstr;

< Method 2 >

CString str("000888");

CHAR pstr[7];
strcpy(pstr, str.GetBuffer(str.GetLength()));

USES_CONVERSION;
WCHAR* wstr = A2W(pstr1);







'Code > C C++' 카테고리의 다른 글

[C++/CLI] Marshalling : System::String^ <-> const char*  (0) 2010.05.17
[C++] polymorphism.h  (0) 2010.05.17
[C++] vector shared_ptr sample  (0) 2010.05.15
[MFC] Simplified MFC Structure  (0) 2010.04.24
[MFC] Simplest MFC Program  (0) 2010.04.23
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함