CStringA/W cheaply and implicitly converted to const char/wchar_t * . Whenever you need a C-style string, just pass the CString object itself (or the result of .GetString() , which is the same). The pointer remains valid until the string object is alive and changed.
strcpy(g_acCameraip[0], strCamIP1);
If you need a rewritable (non-constant) buffer, use .GetBuffer() with an optional argument of maximum length.
If you have CStringW , but you need const char* and vice versa, you can use a temporary CStringA object:
strcpy(g_acCameraip[0], CStringA(strCamIP1).GetString());
But a much better way is to have an array of CString s. You can use them if you need a string with a null character, but they will also manage the string memory for you.
std::vector<CString> g_acCameraip(16); g_acCameraip[0] = theApp.GetProfileString(strSection, _T("IP1"), NULL);
hamstergene
source share