How to create a copy of a list of ints in C++

1 Answer

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

int main()
{
	std::list<int> lst(6, 400);
	std::list<int> lst2(lst);

	for (auto elem : lst2) {
		std::cout << elem << ' ';
	}
	std::cout << std::endl;
	
	return 0;
}

/*
run:

400 400 400 400 400 400

*/

 



answered Dec 30, 2017 by avibootz

Related questions

1 answer 166 views
166 views asked Dec 30, 2017 by avibootz
1 answer 169 views
1 answer 187 views
1 answer 204 views
1 answer 188 views
188 views asked Jan 5, 2018 by avibootz
...