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. #if defined(_WIN32)
  34. # define sprintfp _sprintf_p
  35. #else
  36. # define sprintfp snprintf
  37. #endif
  38.  
  39. std::string GetDateString(
  40. const std::string &langCode,
  41. int month, int day, int year)
  42. {
  43. std::string fmt = GetDateFormatString(langCode);
  44. std::array<char, 32> buffer;
  45. buffer.fill(0);
  46. sprintfp(buffer.data(), 32, fmt.c_str(), month, day, year);
  47. std::string ret = buffer.data();
  48. return ret;
  49. }
  50.  
  51. int main()
  52. {
  53. std::cout << GetDateString("en", 11, 7, 2018) << "\n";
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
11/7/2018