The following code snippet is supposed to output “true” if the string “c++” is in the map and false otherwise. However, it has an error. Describe the error and give a fix.
```
if (mymap["c++"]==0)
{
cout << "false" << endl;
}
else
{
cout << "true" << endl;
}
```
The expression mymap["c++"] creates a new association if one does not already exist. To see if something is in the map we should use the find method, which returns m.end() if there is no such element:
```
if (mymap.find("c++") == mymap.end())
{
cout << "false" << endl;
}
else
{
cout << "true" << endl;
}
```
Computer Science & Information Technology
You might also like to view...
Use the ________ placeholder to insert a company logo into a custom slide layout
A) Picture B) Table C) SmartArt D) Text
Computer Science & Information Technology
?Transmitting a program, code, or command that causes harm to a computer is a crime.
Answer the following statement true (T) or false (F)
Computer Science & Information Technology