Recommendations for string processing in VC ++?

Since I am new to Visual C ++, there are so many types for string handling. When I use some type and continue coding, but in the next step there are built-in functions that use other types, and you always need to convert one type of string to another. I found so many blogs, but am so confused when I see so many answers and try, but some work and some do not.

Please give your answer or links that provide the ultimate solution for handling various types of strings in Visual C ++.

+3
source share
4 answers

, . , , .

  • std::string -, ++.

  • MFC, cstring

  • ++ Cli System:: String

  • api, , cstyle, , , APi, .net

  • , ATL , .

+5

API Win32 LPCWSTR ( NULL- C- wchar_t). API, SetWindowTextA (HWND, LPCSTR) SetWindowTextW (HWND, LPCWSTR), SetWindowText() UNICODE , :

#ifdef UNICODE
#define SetWindowText  SetWindowTextW
#else
#define SetWindowText  SetWindowTextA
#endif // !UNICODE 

API SetWindowTextA() LPCWSTR LPCSTR SetWindowTextW(), , UNICODE wchar_t .

COM- BSTR, , .

, BSTR LPCWSTR MS _bstr_t class: _bstr_t myBstr (/LPCWSTR/psText).

ATL:: CString MFC CString ( ) CStringA CStringW. ( CStringA:: LPCSTR() CStringW:: operator LPCWSTR()), CString API Win32:

CString myStr = _T("Hello");
::SetWindowText(myHwnd, myStr);

std:: [w] , c_str(), :

std::wstring myStr = L"Hello"; // assuming UNICODE defined
::SetWindowText(myHwnd, myStr.c_str());

:

  • UNICODE , Win32.

  • MFC, , , CString, ATL , ATL:: CString, (#include <atlstr.h> ATL) std:: wstring.
  • , std:: wstring.
+2

-, . STL std::string std:: wstring. MFC CString. MFC, CString. unicode , . , , C/++, , Unicode CStrings. , . CStrings ; IMO , std::( ​​w).

BSTR, - COM, .

0

Source: https://habr.com/ru/post/1736610/


All Articles