I have a program which allows the user to input a word they want to search for in the given large text file. The program separates the books inside the text files and counts the number of occurrence of user-input word in each book. After that, user can choose the book so that the program print all the lines in the book which contains the user's word. I was wondering if their is any technique to highlight the search word whenever we print out all the matching line. I am very new to C++ and any kind of help will be appreciated.
Asked
Active
Viewed 77 times
0
-
2You may need a library to do this. standard `c++` has no concept of colors or highlighting text. – drescherjm Dec 10 '19 at 22:20
-
1How are you running your code? And what operating system are you using? If you're on Linux in a terminal, you can use [ANSI color codes](https://stackoverflow.com/a/2616912/2602718). – scohe001 Dec 10 '19 at 22:22
-
I am writing on online compiler – lyatit Dec 10 '19 at 22:25
-
@lyatit Did you try the ANSI color codes that schhe001 gave you a link to? If the online compiler supports color output, I'd start testing with those. (darn - undid my upvote to schhe001's comment - didn't mean to). – Ted Lyngmo Dec 10 '19 at 22:36
-
1Highlighting depends on the console or terminal that is receiving the output. There are many methods for highlighting, if the console or terminal supports highlighting. – Thomas Matthews Dec 10 '19 at 22:48
-
Since you're apparently showing text on a web site, I'd probably use markdown. Markdown is easy to generate, and easy to find code to render it on a web site as well. – Jerry Coffin Dec 10 '19 at 22:58