Check if a file contains a string
Hi,there is a simple way to check if a file contain a string?
Thanks in advance
Open file, read one line, Search that line for a match. Repeat until end of file.
I opened the file from argv and used search string from argv.
To be a little more useful I would add a line count, and when you find a match display the line number as well as the matching line.
while ( std::getline( file, line ) )
if ( line.find( argv ) != std::string::npos )
std::cout << line << std::endl;
Topic archived. No new replies allowed.