I am writing up a function that reverses the order of the string "rdd" to "ddr",
when I run it I get an error that substring is out of range. Any help is appreciated!
Imagine calling this function with an empty string:
size() will return 0;
your attempt to assign -1 to an unsigned then results (probably) in i being set to the maximum positive value of int
your rname[i] is now definitely out of range, since the string is empty
A different scenario, what will happen to i when "i == 0" and you run "i-- "? remember i is unsigned
Consider PP's advice about iterators and maybe look up some information on range for, for_each, etc.
Generally, try and use the proper type for holding the size of the string: