どうも、ちょげ(@chogetarou)です。
Vectorのイテレータの末尾を取得する方法を紹介します。
方法

Vectorのイテレータの末尾を取得するには、end()を使います。
具体的な方法としては、「myVec.end()」のように、Vectorからend()を呼び出します。
//myVec=対象のVector
T first = myVec.end();
上記のend()は、対象のVectorのイテレータの末尾を取得します。
使用例
#include <iostream>
#include <vector>
using namespace std;
int main(void){
vector<string> nums = { "one", "two", "three", "four", "five"};
auto last = nums.end();
--last;
cout << *last << endl;
return 0;
}
出力:
five
コメント