[ create a new paste ] login | about

Link: http://codepad.org/FDw3bEc9    [ raw code | output | fork ]

hecomi - C++, pasted on Jun 18:
// listについての勉強

#include <iostream>
#include <list>

int main()
{
	std::list<int> list;
	for (int i=0; i<10; i++) {
		list.push_back(i);
	}

	std::list<int>::iterator it = list.begin();
	while (it != list.end()) {
		if  (*it == 5) {
			it = list.erase(it);
			it = list.insert(it, 999);
		}
		it++;
	}

	it = list.begin();
	while (it != list.end()) {
		std::cout << *it << std::endl;
		it++;
	}

	// = clear
	while (!list.empty()) {
		list.pop_back();
	}

	std::cout << "list size: " << list.size() << std::endl;

	return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
0
1
2
3
4
999
6
7
8
9
list size: 0


Create a new paste based on this one


Comments: