0

我收到“设置非法间接错误”,但我不知道我做错了什么。我想做的是从具有表单的 input.txt 文件中获取输入

string1 string2
string3 string4
etc.

并将字符串按升序编号,不重复,然后在某些函数中使用它们并将值存储在struct StringInt中。但是我收到了这个奇怪的错误,我不知道从哪里开始修复它。

struct StringInt {
    std::string name;  // associate name and number for each input string
    int number;
};

int main(int argc, char* argv[]) {
  tot_strings = 100;
  std::string vert1, vert2;
  std::set<std::string> inGraph(0, tot_strings);  // this is the set in question
  std::set<std::string>::iterator sit;
  std::vector<StringInt> stringInts(tot_strings);  // Edit: forgot to mention this initially
  StringInt* si;
  int icv1, icv2;

  std::ifstream myfile2 ("input.txt");
  if (myfile2.is_open()) {      
      while(myfile2 >> vert1 >> vert2) {
          myfile2 >> vert1 >> vert2;

  if (inGraph.find(vert1) != inGraph.end()) {  // not sure if I do this correctly
      icv1 = i++;
      si->name = vert1;
      si->number = icv1;
      inGraph.insert(vert1);                   // here's the insert that might be 
      stringInts.push_back(*si);               // causing of the error
  }
  else {
      icv1 = si->number;
  }
  if (inGraph.find(vert2) != inGraph.end()) {
      icv2 = i++;
      si->name = vert1;
      si->number = icv2;
      inGraph.insert(vert2);
      stringInts.push_back(*si);
  }
  else {
      icv1 = si->number;
  }

  // use icv1 and icv2 as int inputs in functions below


}

我有什么意义吗?我该如何解决“设置非法间接错误”?已编辑:包含我在代码中但忘记包含在示例中的 std::vector stringInts(tot_strings) 。

4

0 回答 0