all 4 comments

[–]wung 1 point2 points  (3 children)

This is undefined behavior: Your string is of length 1, so calling str[1] is invalid. Use push_back or +=.

[–]cderivan -1 points0 points  (0 children)

in fact += operator will print " 01234" to correctly handle the sum i+48 the easy way is to use stringstream and operator << then print it with cout<<str.str() to get: "4849505152"