lundi 3 octobre 2016

Better way to convert const wchar_t * to const std::basic_string

I am wondering if there is easier way (less verbose) to convert const char_t* to std::string_t rather than below:

typedef wchar_t  char_t;
typedef basic_string<char_t> string_t;

std::wstring ws(script_->GetName());  //GetName() returns const char_t*
const std::string wsStr(ws.begin(), ws.end());
const std::string_t script_name(wsStr.begin(), wsStr.end());

Any help would be appreciated.

EDIT

#ifdef OS_WIN
#include <tchar.h>
typedef wchar_t  char_t;
#define CHAR_WIDE
#else
typedef char char_t;

Aucun commentaire:

Enregistrer un commentaire