As mentioned in the comments, what you are trying to use requires C ++ 11. This means both a compiler that supports C ++ 11 (for example, GCC 4.7+), and possibly manual inclusion of C ++ 11 (Eg flag -std=c++11 ), so check them both out if you think it should work for you.
If you are stuck in a compiler that does not support C ++ 11, you can use the following to achieve what you want with regular C ++:
string date() { tm timeStruct; int currentMonth = timeStruct.tm_mon + 1; int currentDay = timeStruct.tm_mday; int currentYear = timeStruct.tm_year - 100; char currentDate[30]; sprintf(currentDate, "%02d/%02d/%d", currentMonth, currentDay, currentYear); return currentDate;
Note that for the Day and Month parameters, I used %02d to display at least 2 digits, so 5/1 will actually be represented as 05/01 . If you don't want this, you can simply use %d instead, which will behave like your original to_string . (I'm not sure which format you use for currentYear , but you probably also want to use %02d or %04d for this parameter)
source share