[英]std::bad_alloc on declaration of a list c++
我正在尝试使用列表并创建包含整数的列表的列表。 在运行代码后,它会解决一个错误的alloc异常:
“在抛出'std :: bad_alloc'what()实例之后调用的aterminate:std :: bad_alloc
该应用程序已请求运行时以一种异常方式终止它。 请与应用程序的支持团队联系以获取更多信息。”
#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;
}
我正在使用minGW在Windows 10的Clion中运行它。 我怎样才能解决这个问题? 一切似乎都正确。
我在Visual Studio 2015中编译了您的代码。您的代码进行了编译,没有错误,输出如下。
a1234
结束
5678
结束
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.