Search and highlight a word in c++

Write your question here.
How I can search a word or string text from a text . After that i print the text again but with highlight word that i found

You can put the text in a string and use the string::find function to search for text.

But what are your circumstances?

Where does the text come from? How much of it is there? What does "highlight" mean? How are you presenting the output? Does the text include line breaks? If it does, should those be part of the search?
the text input from users like
string text, value;
cout << " Enter string ";
cin >> text;
cout << " Enter the word or character you want to search ? ";
cin >> value;
And we print the text again but the word u search will be different color or in highlight.
like find" r "in the text : abcderder234
and the text after searching is :
abcde|r|de|r|234
https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
So does this work for you?
1
2
3
int main ( ) {
    cout << "\033[32m" << "This is green" << "\033[m" << " back to normal" << endl;
}

Whilst ANSI escape sequences are commonly supported, the C++ standards make no mention of colour.

So if it doesn't work, then you need to tell us more about your environment.

Topic archived. No new replies allowed.