#include <iostream>
#include <fstream>
int main()
{
std::string line, stringtobeSearched = "blabla";
std::ifstream inFile("input.txt");
if(inFile)
{
while(getline(inFile, line, '\n'))
{
//std::cout<<line<<std::endl;
//if the line read does not contain the string searched for
if(line.find(stringtobeSearched) == std::string::npos)
{
; //do something here
}
//if the line read contains the string searched for then print string found
else
{
std::cout<<"string found "<<std::endl;//just printing it on screen
}
}
}
else
{
std::cout<<"file could not be read"<<std::endl;
}
inFile.close();
return 0;
}
this is first line
this is second blabla
third line is this
blabla again found for second time