Hello,
I was wondering how to convert the __DATE__ macro to a C++ string?
Thanks to any one who replies in advance.
Printable View
Hello,
I was wondering how to convert the __DATE__ macro to a C++ string?
Thanks to any one who replies in advance.
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;
}
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.Quote:
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.