Check if a word is present in a sentence | C ++ implementation of the approach ; Function that returns true if the word is found ; To break the sentence in words ; To temporarily store each individual word ; Comparing the current word with the word to be searched ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isWordPresent ( string sentence , string word ) { stringstream s ( sentence ) ; string temp ; while ( s >> temp ) { if ( temp . compare ( word ) == 0 ) { return true ; } } return false ; } int main ( ) { string s = " Geeks ▁ for ▁ Geeks " ; string word = " Geeks " ; if ( isWordPresent ( s , word ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }