How to iterator form second to element before last (second last) of a list in C++

1 Answer

0 votes
#include <iostream>
#include <list>

using std::list;
using std::cout;
using std::endl;

int main()
{
	list<int> lst{ 1, 3, 8, 23, 88, 12, 99, 7 };
	
	for (list<int>::iterator i = ++lst.begin(), j = --lst.end(); i != j; i++) {
		cout << *i << ' ';
	}

	cout << endl;

}


/*
run:

3 8 23 88 12 99

*/

 



answered Jan 20, 2018 by avibootz

Related questions

...