C++ 当我弹出时,我得到“指针被释放时未分配”错误

C++ 当我弹出时,我得到“指针被释放时未分配”错误,c++,vector,C++,Vector,这是一段我有问题的小代码。 anagram函数返回一个正确的结果,即字符串向量向量和anagram。除了最后一个元素是空的之外,这个向量充满了正确的字谜。因此,我试图弹出它,但我总是得到一个指针被释放,并没有分配错误=/ int main(int argc, const char * argv[]) { Dictionary d = create_dictionary("dico.txt"); vector<vector<string> > v = ana

这是一段我有问题的小代码。 anagram函数返回一个正确的结果,即字符串向量向量和anagram。除了最后一个元素是空的之外,这个向量充满了正确的字谜。因此,我试图弹出它,但我总是得到一个指针被释放,并没有分配错误=/

int main(int argc, const char * argv[]) {
    Dictionary d = create_dictionary("dico.txt");
    vector<vector<string> > v = anagrams("object", d, 0);

    v.pop_back(); //Error here

    return 0; 
}
我到处都找过了,什么也没找到=/ 有人知道它来自哪里吗?谢谢你的时间

以下是我创建字典的方法:

Dictionary create_dictionary(const string& filename) {
    Dictionary d;

    //Read the file and store the words in d.words
    ifstream file(filename.c_str());

    string word;

    if(file.is_open()) {
        while (!file.eof()) {
            file >> word;
            d.words.push_back(word);
        }
    }

    else
        cout << "There is a problem with the file !" << endl;

    file.close();
    return d; }

如果v不为空,则回拨pop_,如:

if (!v.empty())
  v.pop_back(); 

如果你在Linux上,试试valgrind。它来自你的代码。字典,创建字典和/或语法你能发布你自己的实现吗?从anagrams开始dico.txt包含什么?你希望v里面有什么?你介意分享你代码的相关部分吗?你应该边写边归档>>word。使用eof是错误的。但这可能不是问题的原因。是的,特别是在《anagramsHelper》的最后一篇文章中。
if (!v.empty())
  v.pop_back();