As an example:
string s = "123";
s.assign(find(s.begin(),s.end(),'2'), s.end());
Is the behavior of the above code defined? Or it leads to undefined behavior?
Yes. This version of assign is defined as
template<class InputIterator> constexpr basic_string& assign(InputIterator first, InputIterator last);
Constraints: InputIterator is a type that qualifies as an input iterator.
Effects: Equivalent to: return assign(basic_string(first, last, get_allocator()));
which shows a temporary computed before changes taking place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With