Search word in text file in print that role of context

So I need to let the user to input any words he wants to find. For example, in a row of a name list, there will be the name, age, etc etc. The user only has to enter the name and the program will go look into the text file and print it out. What will the C++ code be for this type of request? And what if the text file does not have the data the user wants, how will the program tell the user?
Last edited on
What c++ issues are you having? Can you read test from a file? Can you search std:string? What is the format of the file? What have you attempted so far? Post your current code.
And what if the text file does not have the data the user wants, how will the program tell the user?
Programs like grep and findstr simply print out nothing if the text is not found. The return value from main may also be non-zero.
Last edited on
my home-rolled program like this prints the line number & the line if it matched. But the problem you seem to have is lack of requirement or vision. what do you want it to do? who will use it, and for what? an interactive program may tell the user "no data found" via some sort of printed statement. A utility may be silent, implying nothing found because nothing printed.

Topic archived. No new replies allowed.