#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream ifs("in.txt");
string word = "foo";
string line;
while( getline(ifs, line ))
{
size_t pos = line.find(word);
if ( pos != string::npos)
cout << line << endl;
}
}
[update]
If you don't want foofighters, that is if you need to search your word between word-boundaries (as hinted by yourself and
KarstenK) then you might use a regular expression:
#include <iostream>
#include <fstream>
#include <regex>
using namespace std;
int main ()
{
ifstream ifs("in.txt");
string word = "foo";
std::regex e{"\\b" + word + "\\b"};
string line;
while( getline(ifs, line ))
{
if ( regex_search( line, e) )
cout << line << endl;
}
}
[/update]