Hi

I have been working on a project that requires me to be able to search a file for all occurrences of a string and store the entire line that contains a single occurrence of that string a an array of characters. For example:

Search: web

File:
Time
James
Webster
Web
Theme
Skate
Spider Web

Output:
Webster
Web
Spider Web

I know the DOS command that does something like this but that won't work in this case. Does anyone have any idea how to do this?

Thanks in advance

open the file
read each line
for each line read, search the line for the given word. If you ust std::string to hold the line then use it's find() method. You will probably first have to convert the line to all lower or upper case so that you get case-insensitive compares.

If the word is found then just add it to the array. std::vector is recommended here because it make that process pretty simple.

I know that I probably know how to do this, but I can't remember how to read the file line by line...:?:

funny...

It works great now though. thanks