どうも、ちょげ(@chogetarou)です。
リスト(List)の最初の要素を削除する方法を紹介します。
方法

リスト(List)の先頭の要素を削除するには、pop_front()を使います。
具体的な方法としては、「myList.front()」のように、ドットを使いリスト(List)からfront()を呼び出します。
//myList=対象のリスト
myList.pop_front();
上記のpop_front()は、対象のリスト(List)の先頭の要素を削除します。
使用例
#include <iostream>
#include <list>
using namespace std;
int main(void){
list<string> nums = { "one", "two", "three", "four", "five"};
nums.pop_front();
for (string item: nums) {
cout << item << endl;
}
return 0;
}
出力:
two
three
four
five
コメント