check word is present in a string | C++ | 1 mins

Поделиться
HTML-код
  • Опубликовано: 16 окт 2024
  • In this tutorial, we'll walk you through a simple yet powerful C++ program that checks if a specific word is present in a given string.
    🔍 What You'll Learn:
    The program reads a full sentence and a word from the user using getline(cin, sentence) and getline(cin, word).
    getline is used to handle input with spaces correctly.
    Finding the Word:
    sentence.find(word) searches for the occurrence of word in sentence.
    string::npos is a constant representing a non-existent position. If word is not found in sentence, find returns string::npos.

Комментарии •