Need help with type conversion

Here is the original code:
1
2
3
4
5
6
        // Get the time
        wchar_t timeString[MAX_PATH];
        GetTimeFormatEx(NULL, 0, NULL, L"hh'-'mm'-'ss'-'ms", timeString, _countof(timeString));

        // File name will be KinectSnapshot-HH-MM-SS.bmp
        StringCchPrintfW(screenshotName, screenshotNameSize, L"%s\\KinectSnapshot-%s.bmp", L"C:\\Users\\John\\Desktop\\KinectPhotos", timeString);


What I want do is not use the GetTimeFormatEx() because I need milliseconds and it can't output them so I want to use instead is:

1
2
3
4
        GetLocalTime(&st);
	stringstream ss;
	ss << st.wDay  << '-'<< st.wMonth << '-' << st.wYear << "--" << st.wHour << ':' << st.wMinute << ':' << st.wSecond << ':' << st.wMilliseconds;
	string stemp = ss.str();


My problem is in the conversion from my string stemp to wchar_t timeString[Max_path]
Why not use a wostringstream to format a wstring and be rid of the string conversion?
here's the basic code, you use it for your own code at will:
1
2
3
4
        wchar_t* a;
	string b("test");
	basic_string<wchar_t> c(b.begin(), b.end());
	a=const_cast<wchar_t*>(c.c_str());

It's realy so simple!
Last edited on
yea, I didn't notice kbw's post untill now, so actualy you can make it simpler like this:
1
2
3
4
wchar_t* a;
	string b("test");
	wstring c(b.begin(), b.end());
	a=const_cast<wchar_t*>(c.c_str());

and further:
1
2
3
wchar_t* a;
	string b("test");
	a=const_cast<wchar_t*>(wstring (b.begin(), b.end()).c.c_str());

or even a function:
1
2
3
4
wchar_t* strToWcharP(string str)
{
	return const_cast<wchar_t*>(wstring(str.begin(), str.end()).c_str());
}
Last edited on
Topic archived. No new replies allowed.