fork download
  1. #include <iostream>
  2. #include <regex>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. struct FORMATTER
  8. {
  9. regex s_rule;
  10. string r_rule;
  11. };
  12.  
  13. enum FORMAT_TYPE
  14. {
  15. test,
  16. };
  17.  
  18. const FORMATTER formats[] =
  19. {
  20. { regex( "(\\d{2})(\\d{3})" ), "$1-$2" },
  21. };
  22.  
  23. inline auto format( const FORMAT_TYPE type, const int value )
  24. {
  25. return regex_replace(
  26. to_string( value ), formats[ type ].s_rule, formats[ type ].r_rule );
  27. };
  28.  
  29. int main()
  30. {
  31. cout << format( test, 12345 ) << endl;
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 3504KB
stdin
Standard input is empty
stdout
12-345