fork download
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. std::size_t const count = 3;
  6.  
  7. std::cout << "prefix?" << std::endl;
  8. std::string prefix;
  9. std::cin >> prefix;
  10.  
  11. std::cout << "enter words:" << std::endl;
  12. std::string words[count];
  13. for (std::size_t i = 0; i < count; ++i)
  14. {
  15. std::cin >> words[i];
  16. }
  17.  
  18. std::cout << "results:" << std::endl;
  19. auto prefix_length = prefix.length();
  20. for (std::size_t i = 0; i < count; ++i)
  21. {
  22. auto const& word = words[i];
  23. if (word.length() >= prefix_length && word.substr(0, prefix_length) == prefix)
  24. {
  25. std::cout << word << std::endl;
  26. }
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
prefix?
enter words:
results: