ostringstream to tchar*
-
Hiya, It would be helpful if someone tell me how I could convert ostringstream to tchar* such that it will work in both ansi and unicode compilation. currently i have done like:
std::ostringstream strn;
strn <<"Just do it!";
const TCHAR* tata = static_cast< LPCTSTR >(strn.str().c_str());But this does not seems to work in both the cases.
-
Hiya, It would be helpful if someone tell me how I could convert ostringstream to tchar* such that it will work in both ansi and unicode compilation. currently i have done like:
std::ostringstream strn;
strn <<"Just do it!";
const TCHAR* tata = static_cast< LPCTSTR >(strn.str().c_str());But this does not seems to work in both the cases.
I'd use something like:
// Handle both unicode and ansi builds
#ifdef _UNICODE
typedef std::wstring tstring;
typedef std::wostringstream tostringstream;
#else
typedef std::string tstring;
typedef std::ostringstream tostringstream;
#endif//......
tostringstream strn;
strn << _T("Just do it!");
tstring str = strn.str();
const TCHAR* tata = str.c_str();modified on Wednesday, May 12, 2010 8:48 AM