Hi,
I want to print out the number of seconds returned from a CTimeSpan object.
ie. CTimeSpan::GetTotalSeconds;
I want to print this out in a message box.
How would I cast it??
Thanks.
Ryan
Hi,
I want to print out the number of seconds returned from a CTimeSpan object.
ie. CTimeSpan::GetTotalSeconds;
I want to print this out in a message box.
How would I cast it??
Thanks.
Ryan
To my limited knowledge, a message box only takes C strings. You can use a stringstream to convert a non-string value into a std::string object like so:
Then simply call MessageBox with the c_str() member function of the string class:Code:template <class T> string make_string(T& data) { stringstream ss; ss<< data; return ss.str(); }
Code:MessageBox(NULL, TEXT(make_string(value).c_str()), TEXT("FOO"), MB_OK);
My best code is written with the delete key.
Lookup the CTimeSpan::Format member.
This will return a CString object that can be used in any MessageBox wrapper for MFC
ala
Also, bewareCode:CTime TimeThen,TimeNow; TimeThen = CTime::GetCurrentTime(); ::Sleep(10000); TimeNow = CTime::GetCurrentTime(); CTimeSpan TimeSpan = TimeNow - TimeThen; CString TimeStr = TimeSpan.Format(_T("Number of Seconds: %S")); MessageBox(TimeStr);
The TEXT macro only works for string literalsCode:TEXT(make_string(value).c_str())
If you want your code to be UNICODE safe, use a CString for MFC, or some preprocessor work to define between std::string or std::wstringCode:__TEXT(quote) L##quote
Thanks for the help. It was able to compile without errors but does not give the right returned value.
I am retrieving values of 'datetime' type from SQL and have the following code:
start = CTime(CString(RsITEM(spRS, "start_date")));
spRS->MoveNext();
end = CTime(CString(RsITEM(spRS, "start_date")));
timeDiff = end - start;
TimeStr = timeDiff.Format(_T("Number of Seconds: %S"));
MessageBox(NULL,TimeStr, "Time Elapsed",NULL);
*RsITEM returns a specific cell value from the current row of the recordset 'spRS'
RYAN
At a guess I would say that RsITEM doesnt return a string in the same format as the parameters for the construtor of CTime....
Look on MSDN and see if the formats are different
RsITEM returns values of type "_variant_t"
I need to be able to cast as different types, but can't seem to figure it out?
Any help would be graciously appreciated.
Ryan
Hmm...in that case I'm not sure how it's even compiling! _variant_t has an operator _bstr_t( ) which is converting it to a CString......but CTime doesnt seem to take a string as a construtor....
I'll have a look at this when I'm at home...
Hi,
Sorry, the code i pasted above does not compile. I was jsut trying different things out. It's just to show i guess, what i'm trying to accomplish.
Thanks.
Ryan