hello, how to convert stringw to const char or wchar_t to const char?
Thanks
convert stringw to const char
wchar_t wtemp[255];
wchar_t* ConvertToWChar(char* text)
{
// Convert to a wchar_t*
size_t origsize = strlen(text) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
mbstowcs_s(&convertedChars, wtemp, origsize, text, _TRUNCATE);
return wtemp;
}
char mbtemp[255];
char* ConvertToMultiByte(wchar_t* text)
{
size_t i;
wcstombs_s(&i,mbtemp,(size_t)255,text,(size_t)255);
mbtemp[i-1] = '\0';
return mbtemp;
}
wchar_t* ConvertToWChar(char* text)
{
// Convert to a wchar_t*
size_t origsize = strlen(text) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
mbstowcs_s(&convertedChars, wtemp, origsize, text, _TRUNCATE);
return wtemp;
}
char mbtemp[255];
char* ConvertToMultiByte(wchar_t* text)
{
size_t i;
wcstombs_s(&i,mbtemp,(size_t)255,text,(size_t)255);
mbtemp[i-1] = '\0';
return mbtemp;
}
-
- Posts: 39
- Joined: Thu Jan 11, 2007 2:45 am
following error
I am using the dev c + +
Code: Select all
funcoes.h: In function `wchar_t* ConvertToWChar(char*)':
funcoes.h:13: error: `_TRUNCATE' undeclared (first use this function)
funcoes.h:13: error: (Each undeclared identifier is reported only once for each function it appears in.)
funcoes.h:13: error: `mbstowcs_s' undeclared (first use this function)
funcoes.h: In function `char* ConvertToMultiByte(wchar_t*)':
funcoes.h:21: error: `wcstombs_s' undeclared (first use this function)
I am using the dev c + +