Set illegal indirection error?

2019-08-30 02:52发布

I'm getting a "set illegal indirection error" but I can't figure out what I am doing wrong. What I am trying to do is take input from input.txt file that has a form

string1 string2
string3 string4
etc.

And number the strings in ascending order without duplicates, then use them in some functions and store the values in struct StringInt. But I am getting this weird error and I don't know where to start fixing it.

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


}

Does what I have make sense and how can I go about fixing the "set illegal indirection error"? Edited: included std::vector stringInts(tot_strings) that I had in my code but forgot to include in the example.

标签: c++ input
0条回答
登录 后发表回答