I have confirmed it with writing the resultant data in to the file(not printing it on console).The actual requirement of this function was to convert LPCTSTR to char* since I want the resultant string in character buffer.
Can anyone please correct me what I have done wrong in it?
(e.g. val points to "c++ では、偉大な言語である。")
Expand|Select|Wrap|Line Numbers
- char* conversion(LPCTSTR val)
- {
- LPCWSTR wstr = val;
- int count = wcslen(wstr);
- char* c = new char[count + 1];
- wchar_t* pwchr = const_cast<wchar_t*> (&wstr[0]);
- for(int j = 0; j < count; ++j)
- {
- c[j] = static_cast<char> (*pwchr);
- pwchr++;
- }
- c[count] = '\0';
- wchar_t *op;
- wcstombs(c,val,count);
- return c;
- }