Remove leading zeros from a Number given as a string | C ++ Program to implement the above approach ; Function to remove all leading zeros from a a given string ; Regex to remove leading zeros from a string ; Replaces the matched value with given string ; Driver Code
#include <iostream> NEW_LINE #include <regex> NEW_LINE using namespace std ; void removeLeadingZeros ( string str ) { const regex pattern ( " ^ 0 + ( ? ! $ ) " ) ; str = regex_replace ( str , pattern , " " ) ; cout << str ; } int main ( ) { string str = "0001234" ; removeLeadingZeros ( str ) ; return 0 ; }