我正在创建一个使用stings向量作为成员变量的windows应用程序。出于某种原因,我可以编译,但当它试图获取任何向量时,成员都会崩溃。错误为0xC0000005:访问冲突读取位置0xcdcdcdd9。在vector类的成员函数中。
这是size()函数的中断点。
size_type capacity() const
{ // return current length of allocated storage
return (this->_Myend - this->_Myfirst);
}
我使用的是visual studios 2010。
谢谢你,姜戈
发布于 2010-05-19 10:14:46
我以前遇到过这样的事情。最有可能的原因是堆损坏。
发布于 2010-05-19 09:25:24
问题不在于STL代码,而在于您的代码。
由于您没有粘贴代码,因此我将向您展示一个如何使用字符串向量的示例。
std::vector<std::string> v;
v.push_back("hello");
v.push_back("world!");
//Note the above 2 string literals get implicitly converted to std::string
assert(v.size() == 2);
assert(v[0] == "hello");
发布于 2010-05-19 09:44:12
在标题中。
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Chat
{
protected:
vector<string> m_buffers;
public:
Chat();
~Chat();
};
在cpp中
Chat::Chat(){
string init = "test";
m_buffers.push_back(init); //crash
}
Chat::~Chat(){
}
很抱歉缺少代码...我在想什么(手掌)
https://stackoverflow.com/questions/2862236
复制相似问题