Hello,
I was wondering how to convert the __DATE__ macro to a C++ string?
Thanks to any one who replies in advance.
Hello,
I was wondering how to convert the __DATE__ macro to a C++ string?
Thanks to any one who replies in advance.
I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.
You mean the obvious way doesn't work?
Code:#include <iostream> #include <string> int main() { std::string foo = __DATE__; std::cout << foo << std::endl; return 0; }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Yep, the obvious way does not work in my compiler.
I get a compiler error that says
at the assign line, though before reading your post, I had tried using the string += operator and it produced the above error. Then, after reading your post, I changed the code to assign a new string the __DATE__ macro, then add the new string to the output string using the += operator, but it still produced the same error at the assign line as it did at the append line.error: expected primary-expression before ';' token
EDIT: Nevermind...it turned out I had written #define __DATE__ at the top of the file. Once I removed that, it compiled no problems.
Last edited by Programmer_P; 01-17-2011 at 02:03 PM.
I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.