I am trying to truncate beginning zeros from a string, so I used sequence erase function 

`string& erase (size_t pos = 0, size_t len = npos);`

This is my implementaion: 

```
    string str="000010557";
            for(char c:str){
            cout<<c<<" "<<str<<" "<<"\n";// for debug purpose
            if(c=='0')
                str.erase(0,1);
            else
                break;

        }
        cout<<str;

```

the output string that I got is `0010557` instead of`10557` and debug statements prints:

```
0 000010557 
0 00010557 
1 0010557 

```

I read the documentation of [erase](http://www.cplusplus.com/reference/string/string/erase/) and [this](https://stackoverflow.com/questions/28226836/does-using-the-erase-function-in-a-string-invalidate-iterators) post thinking might there be some iterator invalidation but implementing the code snippet recommended in the accepted answer also gave the same output, please help me understand where is the problem.

I am new to using stl library functions, so please forgive any negligence of mine,Thanks.