Q:

How do I find a complete word (not part of it) in a string in C++

In a C++ code, I'm trying to search for a word in a sentence but it keeps doing partial search. I want it to search only for the complete word not parts of it too, any help?
size_t kk;
string word="spo";
string sentence="seven spoons";

kk=sentence.find(word);
if (kk !=string::npos)
cout << "something" << endl;

A:

It sounds like what you want is handled by the concept of word boundaries or word characters in regular expressions.
Here's a program that will return only a complete match. That is, it will only return a word if that word completely matches the exact word you're searching for. If some word in sentence has your target word as a strict substring then it will not be returned. 
#include <regex>
#include <string>
#include <iostream>

int main() {
  std::string word = "spo"; // spo is a word?
  std::string sentence = "seven spoons";

  std::regex r("\\b" + word + "\\b"); // the pattern \b matches a word boundary
  std::smatch m;

  if (std::regex_search(sentence, m, r)) { // this won't find anything because 'spoons' is not the word you're searching for
    std::cout << "match 1: " << m.str() << '\n';
  }

  sentence = "what does the word 'spo' mean?";    
  if (std::regex_search(sentence, m, r)) { // this does find the word 'spo'
    std::cout << "match 2: " << m.str() << '\n';
  }
}

Or alternatively maybe you mean you want to find any word that matches a partial word you're searching for. regex can do that as well:
  std::string partial_word = "spo";
  std::regex r("\\w*" + partial_word + "\\w*"); // the pattern \w matches a word character

This produces:
match 1: spoons
match 2: spo

A:

I think the best way is to split your string using whitespace and punctuation characters as delimiters, then use std::find on the result.
#include <boost/algorithm/string.hpp>
#include <vector>
#include <string>
#include <algorithm>

int main()
{
    std::string word="spo";
    std::string sentence="seven spoons";
    std::vector<std::string> words;
    boost::split(words, sentence, boost::is_any_of("\n\t .,!?\"()"));
    auto match = std::find(begin(words), end(words), word);
    if (match != end(words))
    {
        // Found it!
    }
    else
    {
        // Not there.
    }
 }

