I'm trying to play around with lists and create a list of lists that contain integers. After I run the code it thorws a bad alloc exception:
"aterminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information."
#include <iostream>
#include <list>
#include <string>
int main() {
std::list<int> l{1,2,3,4};//
std::list<int> l1{5,6,7,8};
std::list<std::list<int>> ll;// list of lists<int>
std::cout << "a"; //does not reach here, terminated before this row
ll.push_back(l);
ll.push_back(l1);
std::list<std::list<int>>::iterator itr;
for (itr=ll.begin(); itr != ll.end(); itr++)
{
std::list<int>tl=*itr;
std::list<int>::iterator it;
for (it=tl.begin(); it != tl.end(); it++)
{
std::cout<<*it;
}
std::cout<<std::endl<<"End"<<std::endl;
}
return 0;
}
I'm running it in Clion on Windows 10 with minGW. How can I fix this? everything seems right.