I have a map and am doing a check to see if key exists and if so, get the value. Program is crashing and getting the following error from Visual Studio. "Debug Assertion Failed. map/set iterator not dereferencable".
fasta_map::iterator key; // fasta_map defined as std::map<std::string, std::string>
std::cout << "Sample: ";
std::cin >> sample; //key
while (data.find(sample) == data.end()) {
std::cout << "Sample not found. Try again or press -1 to view list of samples: ";
std::cin >> sample;
if (sample == "-1") {
get_samples();
std::cin >> sample;
}
}
//Program crashes here
dna = data.at(sample);
size = dna.length();
The map is already defined. The variable sample, that I'm getting from the user, is the key to be used to get a value from the map. The while loop is to check if the sample(key) is in the map. get_sample() lists valid keys