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;
}
```
You might also like to view...
E-grass includes electronic trash, such as discarded computer components.
Answer the following statement true (T) or false (F)
Overallocating resources may lead to project failure because the work will likely not get done in the time it was scheduled
Indicate whether the statement is true or false
Which two elements can only exist in support of or as an enhancement to the other elements?
What will be an ideal response?
A page with too many graphical elements might take a long time to load, which could cause visitors to leave your website.
Answer the following statement true (T) or false (F)