convert stringw to const char

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
giuseppegam
Posts: 39
Joined: Thu Jan 11, 2007 2:45 am

convert stringw to const char

Post by giuseppegam »

hello, how to convert stringw to const char or wchar_t to const char?

Thanks
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

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;
}
giuseppegam
Posts: 39
Joined: Thu Jan 11, 2007 2:45 am

Post by giuseppegam »

following error

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 + +
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

search this forum for your answer. using the built in irr string should do what you want, but i personally dont use it so i cannot help with it.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

stringw wstr = L"blah";
stringc str = wstr.c_str();
char* cstr = str.c_str();
Image Image Image
Post Reply