pborawski

Sprawdzanie czy dwa lancuchy znakowe sa w tekscie

Jul 27th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. bool szukaj( std::string & tekst, std::string wyraz1, std::string wyraz2 )
  5. {
  6. size_t pozycja1 = tekst.find( wyraz1 );
  7. size_t pozycja2 = tekst.find( wyraz2 );
  8. if( pozycja1 != std::string::npos && pozycja2 != std::string::npos)
  9. {
  10. return true;
  11. }
  12. return false;
  13. }
  14.  
  15. void wypiszWynik( bool czyZnaleziono )
  16. {
  17. if( czyZnaleziono )
  18. std::cout << "Znaleziono" << std::endl;
  19. else
  20. std::cout << "Nie znaleziono" << std::endl;
  21.  
  22. }
  23.  
  24. int main()
  25. {
  26. std::string napis = "Zadanie domowe z kursu C++ (http://cpp0x.pl) - najlepszy kurs C++ w Internecie!";
  27. wypiszWynik( szukaj( napis, "ada", "kurs" ) );
  28. wypiszWynik( szukaj( napis, "ada", "taki" ) );
  29. wypiszWynik( szukaj( napis, "C++", "cpp0x" ) );
  30. wypiszWynik( szukaj( napis, "C#", "cpp0x" ) );
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment