fork download
  1. #include <array>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. std::string GetDateFormatString(const std::string& langCode)
  6. {
  7. if (
  8. 0 == langCode.compare(0, 2, "en")
  9. || 0 == langCode.compare(0, 2, "EN")
  10. )
  11. {
  12. return std::string("%1$i/%2$i/%3$i");
  13. }
  14. else if (
  15. 0 == langCode.compare(0, 2, "fr")
  16. || 0 == langCode.compare(0, 2, "FR")
  17. )
  18. {
  19. return std::string("%2$i/%1$i/%3$i");
  20. }
  21. else if (
  22. 0 == langCode.compare(0, 2, "ja")
  23. || 0 == langCode.compare(0, 2, "JA")
  24. || 0 == langCode.compare(0, 2, "jp")
  25. || 0 == langCode.compare(0, 2, "JP")
  26. )
  27. {
  28. return std::string("%3$i/%2$i/%1$i");
  29. }
  30. return std::string("%1$i/%2$i/%3$i");
  31. }
  32.  
  33. std::string GetDateString(
  34. const std::string& langCode,
  35. int month, int day, int year)
  36. {
  37. std::string fmt = GetDateFormatString(langCode);
  38. std::array<char, 32> buffer;
  39. buffer.fill(0);
  40. #if defined(_WIN32)
  41. ::_sprintf_p(buffer.data(), 32, fmt.c_str(), month, day, year);
  42. #else
  43. ::sprintf(buffer.data(), fmt.c_str(), month, day, year);
  44. #endif
  45. std::string ret = buffer.data();
  46. return ret;
  47. }
  48.  
  49. int main()
  50. {
  51. std::cout << GetDateString("en", 11, 7, 2018) << "\n";
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
11/7/2018