fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. string sCurrentTime;
  6. time_t ltime;
  7. struct tm *newtime;
  8. char locTime[8 + 1];
  9. time(&ltime);
  10. newtime = localtime(&ltime);
  11. sprintf(locTime, "%04d%02d%02d", newtime->tm_year+1900, newtime->tm_mon+1, newtime->tm_mday); // YYYYMMDD
  12. sCurrentTime = locTime;
  13.  
  14. std::string yydd = "5056";
  15. unsigned short day = 0;
  16. unsigned short month = 1;
  17. unsigned short days_in_month[12] = {31, (unsigned short)((stoi(sCurrentTime.substr(0, 3) + yddd[0]) % 4) == 0 ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  18.  
  19. for (int i=0; i<12; i++) {
  20. if (day - days_in_month[i] <= 0) {
  21. break;
  22. } else {
  23. month++;
  24. day -= days_in_month[i];
  25. }
  26. }
  27. string yyyymmdd = sCurrentTime.substr(0,3) + yddd[0] + ((month < 10) ? "0" + toString<unsigned short>(month) : toString<unsigned short>(month)) + ((day < 10) ? "0" + toString<unsigned short>(day) : toString<unsigned short>(day));
  28.  
  29. std::cout << yyyymmdd;
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:11:98: error: 'sprintf' was not declared in this scope
       sprintf(locTime, "%04d%02d%02d", newtime->tm_year+1900, newtime->tm_mon+1, newtime->tm_mday); // YYYYMMDD
                                                                                                  ^
prog.cpp:17:94: error: 'yddd' was not declared in this scope
   unsigned short days_in_month[12] = {31, (unsigned short)((stoi(sCurrentTime.substr(0, 3) + yddd[0]) % 4) == 0 ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
                                                                                              ^
prog.cpp:17:101: error: 'stoi' was not declared in this scope
   unsigned short days_in_month[12] = {31, (unsigned short)((stoi(sCurrentTime.substr(0, 3) + yddd[0]) % 4) == 0 ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
                                                                                                     ^
prog.cpp:27:80: error: 'toString' was not declared in this scope
   string yyyymmdd = sCurrentTime.substr(0,3) + yddd[0] + ((month < 10) ? "0" + toString<unsigned short>(month) : toString<unsigned short>(month)) + ((day < 10) ? "0" + toString<unsigned short>(day) : toString<unsigned short>(day));
                                                                                ^
prog.cpp:27:89: error: expected primary-expression before 'unsigned'
   string yyyymmdd = sCurrentTime.substr(0,3) + yddd[0] + ((month < 10) ? "0" + toString<unsigned short>(month) : toString<unsigned short>(month)) + ((day < 10) ? "0" + toString<unsigned short>(day) : toString<unsigned short>(day));
                                                                                         ^
prog.cpp:27:89: error: expected ':' before 'unsigned'
prog.cpp:27:89: error: expected primary-expression before 'unsigned'
prog.cpp:27:89: error: expected ')' before 'unsigned'
stdout
Standard output is empty