string::erase alternative

Is there any alternative for erasing a string character when using a loop and still manage to keep the last character? I'm trying to do this in a for loop in my extraction operator overloading. The addition work well but the last character in the string array is not displayed for example, 1256 + 1000 will return 225[?]. Not sure how to go about this

1
2
3
4
for (int i = s.size()-1 ; i >= 0; --i) {
          n.digits[i] = s[0] - '0';
          s.erase(0, 1);
      }
I don't follow. What are you trying to do? The code you have shown us doesn't display any values. What are you trying to do with the string?
The string is the input extracted from the stream

1
2
3
4
5
6
7
8
9
10
11
12
istream& operator>> (istream& in, RLint& n) {
    string s;
    if (in >> s) {
        
        n = 0;
        for (int i = s.size()-1 ; i >= 0; --i) {
            n.digits[i] = s[0] - '0';
            s.erase(0, 1);
        }
    }
    return in;
} 
Last edited on
I actually figured that it's not the source of error in my code. Thanks
Last edited on
Topic archived. No new replies allowed.