Answers for "c++ convert string to const char*"

C++
2

std string to const char * c++

std::string a = "string";
const char* b = a.c_str();
Posted by: Guest on November-12-2020
0

c++ convert const char* to LPCWSTR

const char *p = "D:\";
  const WCHAR *pwcsName; //LPCWSTR
  
  // required size
  int size = MultiByteToWideChar(CP_ACP, 0, p, -1, NULL, 0);
  // allocate it
  pwcsName = new WCHAR[nChars];
  MultiByteToWideChar(CP_ACP, 0, p, -1, (LPWSTR)pwcsName, size);
  // use it....
    
  // delete it
  delete [] pwcsName;
}
Posted by: Guest on February-25-2020

Browse Popular Code Answers by Language