Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,994 questions

51,939 answers

573 users

How to remove a section from a list in C++

1 Answer

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

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

template <typename T>
inline void print(const T &data)
{
	for (const auto &element : data) {
		cout << element << ' ';
	}
	cout << endl;
}

int main()
{
	list<int> lst = { 1, 2, 3, 4, 5, 6, 7 };
	list<int>::iterator it1, it2;

	it1 = it2 = lst.begin();

	advance(it1, 2);
	advance(it2, 5);
	
	lst.erase(it1, it2);

	print(lst);
}

/*
run:

1 2 6 7

*/

 



answered Jan 25, 2018 by avibootz

Related questions

1 answer 99 views
99 views asked Nov 17, 2023 by avibootz
1 answer 98 views
98 views asked Nov 17, 2023 by avibootz
1 answer 109 views
1 answer 208 views
208 views asked Jul 28, 2017 by avibootz
1 answer 155 views
155 views asked Dec 4, 2018 by avibootz
2 answers 180 views
180 views asked Jan 6, 2017 by avibootz
...