C ++ Deque cend()函數(shù)返回一個常量迭代器,它指向容器的最后一個元素的下一位置。迭代器可以遞增或遞減,但不能修改雙端隊列的內(nèi)容。
如果容器為空,則cend()函數(shù)返回的內(nèi)容與cbegin()函數(shù)相同。
const_iterator cend();
它不包含任何參數(shù)。
它返回一個常量迭代器,該常量引用雙端隊列中的最后一個元素的下一位置。
讓我們看一個簡單的示例,當雙端隊列包含字符值時。
#include <iostream>
#include<deque>
using namespace std;
int main()
{
deque<char> ch={'j','a','v','a','T','p','o','i','n','t'};
deque<char>::const_iterator itr=ch.cbegin();
while(itr!=ch.cend())
{
cout<<*itr;
cout<<" ";
++itr;
}
return 0;
}輸出:
j a v a T p o i n t
在此示例中,使用cend()函數(shù)在整個雙端隊列容器中進行迭代,而while循環(huán)將一直執(zhí)行,直到和除非'itr'等于ch.cend()。
讓我們看一個簡單的示例,當雙端隊列包含整數(shù)值時。
#include <iostream>
#include<deque>
using namespace std;
int main()
{
deque<int> deq={100,200,300,400,500};
deque<int>::const_iterator itr=deq.cbegin();
while(itr!=deq.cend())
{
cout<<*itr;
cout<<" ";
++itr;
}
return 0;
}輸出:
100 200 300 400 500
在此示例中,使用cend()函數(shù)在整個雙端隊列容器中進行迭代,而while循環(huán)將一直執(zhí)行,直到'itr'不等于deq.cend()。