fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4. #include <string>
  5.  
  6. int main()
  7. {
  8. std::vector<std::string> words
  9. {
  10. "chuffed",
  11. "apparent",
  12. "buckle",
  13. "awful",
  14. "besides",
  15. "check",
  16. };
  17.  
  18. std::string input;
  19.  
  20. while (std::cout << "Enter a word\n> " && std::cin >> input && input != "quit")
  21. {
  22. auto it = std::find(words.begin(), words.end(), input);
  23.  
  24. if (it != words.end())
  25. std::cout << '"' << input << "\" is string number " << (it - words.begin()) + 1 << '\n';
  26. else
  27. std::cout << '"' << input << "\" is not found!\n";
  28. }
  29. }
Success #stdin #stdout 0s 3436KB
stdin
narnia
buckle
check
apparent
lucifer
quit
stdout
Enter a word
> "narnia" is not found!
Enter a word
> "buckle" is string number 3
Enter a word
> "check" is string number 6
Enter a word
> "apparent" is string number 2
Enter a word
> "lucifer" is not found!
Enter a word
>