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[1] and used search string from argv[2].

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.


1
2
3
4
5
6
7
	while ( std::getline( file, line ) )
	{
		if ( line.find( argv[2] ) != std::string::npos )
		{
			std::cout << line << std::endl;
		}
	}
Topic archived. No new replies allowed.