简体   繁体   English

在抛出 'std::bad_alloc' 的实例后调用终止 what(): std::bad_alloc 在推回向量后

[英]terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc after pushing back into a vector

I'm facing a problem here, I've declared a pointer to a vector.我在这里遇到了一个问题,我已经声明了一个指向向量的指针。 After element insertion, it shows me this error插入元素后,它向我显示此错误

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Here is my code:这是我的代码:

vector<string>* strategies;

cout << "Name of the player 1 : ";
cin >> name;

strategies->push_back(name);

I hope you'd have declared string name;我希望你已经声明了string name;

second, you are creating a pointer but not doing new() of some vector to which *strategies pointer really points.其次,您正在创建一个指针,但没有执行*strategies指针真正指向的某个向量的new() if all your purpose is to insert an element in vector then you really don't need a pointer rather you need object of vector<string> code如果您的所有目的是在向量中插入一个元素,那么您真的不需要指针,而是需要vector<string>的 object代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收到错误“在抛出&#39;std::bad_alloc&#39;what() 的实例后调用终止:std::bad_alloc” - getting error "terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc" 在抛出'std :: bad_alloc'的实例后调用终止what():std :: bad_alloc中止 - terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted 在抛出“ std :: bad_alloc”实例的what():std :: bad_alloc实例后终止调用 - terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc" 在抛出&#39;std::bad _alloc&#39; what(): std::bad_alloc in c++ 实例后调用终止 - Terminate called after throwing an instance of 'std::bad _alloc' what(): std::bad_alloc in c++ 为什么在抛出'std :: bad_alloc'的实例后终止调用? - why terminate called after throwing an instance of 'std::bad_alloc'? Node.js错误“在抛出&#39;std :: bad_alloc&#39;的实例后调用终止what():std :: bad_alloc” - Node.js error “terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc” 在运行我的代码时显示在抛出 'std::bad_alloc' what() 实例后调用终止:std::bad_alloc - On running my code is showing terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc C++ 错误:在抛出 'std::bad_alloc' what(): std::bad_alloc 的实例后调用终止 - C++ error: terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc 如何修复 C++ 错误:在抛出“std::bad_alloc”实例后调用终止。 什么():std::bad_alloc - How to fix C++ error: terminate called after throwing an instance of 'std::bad_alloc'. what(): std::bad_alloc 抛出&#39;std :: bad_alloc&#39;实例后调用Mergemap终止 - Mergemap terminate called after throwing an instance of 'std::bad_alloc'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM