Quiz: Searching
The key is in the backpack, so this program should print You open the door. But it prints The door is locked. Click the line with the mistake.
1#include <iostream>
2#include <algorithm>
3#include <string>
4#include <vector>
5
6int main() {
7 std::vector<std::string> backpack = {"key", "rope", "torch"};
8 auto it = std::find(backpack.begin(), backpack.end(), "key");
9 if (it != backpack.begin()) {
10 std::cout << "You open the door" << std::endl;
11 } else {
12 std::cout << "The door is locked" << std::endl;
13 }
14 return 0;
15}