我收到了“设置非法间接错误”,但我无法弄清楚我做错了什么。 我想要做的是从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),我在我的代码中但忘了包含在示例中。