fork(10) download
  1. #include <iostream>
  2.  
  3. template <typename T_STR, typename T_CHAR>
  4. T_STR remove_leading(T_STR const & str, T_CHAR c)
  5. {
  6. auto end = str.end();
  7.  
  8. for (auto i = str.begin(); i != end; ++i) {
  9. if (*i != c) {
  10. return T_STR(i, end);
  11. }
  12. }
  13.  
  14. // All characters were leading or the string is empty.
  15. return T_STR();
  16. }
  17.  
  18. int main() {
  19. std::string x = "0000000057";
  20. std::string trimmed = remove_leading(x, '0');
  21.  
  22. std::cout << "In:" << x << " Out:" << trimmed << std::endl;
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
In:0000000057 Out:57