I am observing segmentation fault in the following snippet of code:
void read_mdl(const std::string& fname) {
std::ifstream f(fname);
std::unordered_map<int, std::vector<double>> pt_;
while(f) {
int xi = -1;
int pa = 0;
double score = -1;
f >> xi >> pa >> score;
if(xi == -1) { break; }
std::unordered_map<int, std::vector<double>>::iterator it = pt_.find(pa);
std::cout << xi << " " << pa << " " << score << std::endl;
if (it != pt_.end()) {
pt_.insert(std::make_pair(pa, std::vector<double>(n_, 0)));
}
(it->second)[xi] = score; // causing segmentation fault
}
}
Error occurs while accessing the value associated with the key in the unordered map. Any pointers as where I am making the mistake?
Aucun commentaire:
Enregistrer un commentaire