This commit is contained in:
2022-02-01 20:29:15 +08:00
parent cfa10b4e37
commit 0c8dba0a0a
2 changed files with 21 additions and 0 deletions

View File

@@ -24,3 +24,16 @@ bool cpp2c::string2char(std::string inp, char*& out) {
out = temp;
return true;
}
bool cpp2c::string2char(std::wstring inp, wchar_t*& out) {
size_t le = inp.length();
wchar_t* temp = (wchar_t*)malloc((le + 1) * sizeof(wchar_t));
if (!temp) {
printf("Out of memory.\n");
return false;
}
memcpy(temp, inp.c_str(), le * sizeof(wchar_t));
temp[le] = 0;
out = temp;
return true;
}