fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <boost/format.hpp>
  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 GetDateStringBoost(
  34. const std::string &langCode, int month, int day, int year)
  35. {
  36. std::string fmt = GetDateFormatString(langCode);
  37. std::string ret = boost::str(boost::format(fmt) % month % day % year);
  38. return ret;
  39. }
  40.  
  41. int main()
  42. {
  43. std::cout << GetDateStringBoost("en", 11, 7, 2018) << "\n";
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 15280KB
stdin
Standard input is empty
stdout
11/7/2018