Hi, y'all! I'm stuck with the following problem: I want to get the name of an employee by user input and then put in structure, but I can't figure out how to do this properly, so when I assign a value of some employee just like this:
it works fine, but when I trying to make an opportunity to input name by the user my while loop doesn't breaks when I enter an existing value in a map, it seems like he doesn't check "str" variable at all. Also, I get an error "map/set iterator not dereferencable" when trying to insert element into structure after while loop:
1 2 3 4 5 6 7 8 9 10 11
constint size = 20;
constchar *str;
while (!Employees.count(str)) {
cout << "Jill V. found" << Employees.count("Jill V.") << endl; // 1
cout << "Dummy found" << Employees.count("dummy") << endl; // 0
cin.getline(str, size); // enter "Jill V" but while loop continue executing
}
...
Node* p = new Node;
p->name = Employees.find(str)->first;
p->data = Employees.find(str)->second;
cout << Thanks in advance for any help and suggestions you can provide" << endl;
replace const char* with std::string as the key-value-type in the map<...>
comparing 2 char pointers will always fail, until the 2 pointer point to the same memory address, even if the 2 different char pointers point to the same text / content
comparing 2 std::strings on the other hand will give you the desired result