分段错误c ++与字符串数组

1 c++ arrays segmentation-fault bounds

当我运行程序时,我收到了Segmentation Fault错误.我相信它来自于我如何使用在类定义中私有声明的数组"string*words".我在.cpp文件中使用它,任何人都知道我需要改变什么?继承我认为问题所在的功能:

Dictionary::Dictionary(string filename){

    ifstream inF;

    inF.open(filename.c_str());

    if (inF.fail()){
      cerr << "Error opening file" <<endl;
      exit(1);
    }

    inF >> numwords;
    numwords = 3000;
    words = new string(words[numwords]);


    for(int i=0; i <= numwords - 1; i++){
      inF >> words[i];
    }
    inF.close();
  }
Run Code Online (Sandbox Code Playgroud)

yan*_*yan 9

这条线:

words = new string(words[numwords]);
Run Code Online (Sandbox Code Playgroud)

应该是:

words = new string[numwords];
Run Code Online (Sandbox Code Playgroud)