I've read a lot of questions here on SO about how to clear a string entirely (i.e. resetting the capacity, freeing memory). My question though is the exact opposite; is there any reliable way of resetting a string (the length) while being guaranteed that its capacity is kept intact?
Example: reusing a temporary string in a loop.
Likely this will happen by default if I do something like
str.clear()
str.reserve(256)
in each loop iteration, at least when using Visual Studio according to the answer to this post: Specific behaviour of std::string on visual studio?
But relying on "likely" seems a bit risky.