fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4.  
  5. int main() {
  6. std::string ID1 = "111223333";
  7. std::string ID2 = "222114444";
  8.  
  9. auto printDashes = [](const std::string& id) {
  10. std::ostringstream out;
  11. for (std::string::const_iterator it = id.begin(); it != id.end(); ++it) {
  12. switch (std::distance(id.begin(), it)) {
  13. case 3:
  14. case 5:
  15. out << '-';
  16.  
  17. default:
  18. out << *it;
  19. }
  20. }
  21. return out.str();
  22. };
  23.  
  24. std::cout << printDashes(ID1) << std::endl;
  25. std::cout << printDashes(ID2) << std::endl;
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
111-22-3333
222-11-4444