string(iter1, iter2);
第一点:两个迭代器必须指向同一个容器。
第二点:iter2必须>=iter1。
第三点:如果iter1等于iter2,那么结果为空[]
另外一个比较特殊的关于反向迭代器的非常有用知识点,用如下程序来说明:
int main() {
string str1 = "abc";
cout << "str1.rend() - str1.rbegin() is " << str1.rend() - str1.rbegin() << endl;
cout << "str1.rbegin() - str1.rend() is " << str1.rbegin() - str1.rend() << endl;
cout << "*str1.rbegin() is " << *str1.rbegin() << endl;
cout << string(str1.rbegin(), str1.rend()) << endl;
//cout << *str1.rend() << endl; error
//cout << string(str1.rend(), str1.rbegin()) << endl; error
getchar();
}
output is
str1.rend() - str1.rbegin() is 3
str1.rbegin() - str1.rend() is -3
*str1.rbegin() is c
cba