I am trying use std::copy to copy from two different iterator. But during course of execution these two iterators can be pointing to same location. Why in this situation they do not copy the single characters.
std::string str1 = "ABC";
std::string::iterator itr1 = str1.begin();
std::string::iterator itr2 = str1.begin();
std::string result;
std::copy(itr1,itr2,result.begin());
The right bound of the range in STL is not inclusive. If you give it the same iterator twice, the result is an empty range. You want this:
But then, beware that you are writing to a location with no reserved memory, which is Undefined behavior. You must use a
back_insert_iterator