|
-
February 27th, 2008, 12:59 AM
#1
how can i convert DateTime value to string in C++
//this is my demo program
using namespace System;
using namespace System::IO;
void main()
{
DateTime dt = Directory::GetLastWriteTime( "C:\\debug.log" );
//char str[] = (char)dt;
string strTemp;
}
i want to convert the dt value to a string,
i tried converting to char array it failed.
pls do help me.
Thanks in Advance
-
February 27th, 2008, 10:17 AM
#2
Re: how can i convert DateTime value to string in C++
No, No, No...
Do you even realized what you commented out does?
[CODE]
char str[] = (char)dt;
[\CODE]
(char)dt is a single character, being the first character in the dt string.
On second thought, I don't even think it does that.
You see, DateTime is an entire structure.
Typecasting to a char will just take the most significant byte of the entire structure.
Look up the structure if you don't believe me.
Of course, that doesn't do what you want.
use the ToString method like this:
[CODE]
std::string str = dt.ToString();
[\CODE]
Remember this is a C++ string, so you must #include <string>
Print it out with cout
Last edited by sjaycohn; February 27th, 2008 at 10:20 AM.
Reason: Correctness
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|