The while loop should test if the ifstream is at eof or an error using good(). getline only returns the file stream not a boolean expression.
int main()
{
string _search;
string line;
ifstream read;
int i =0;
while(i++<2)
{
cout<<"Enter the word to search"<<endl;
cin>>_search;
read.open("type.txt");
size_t pos,i=0;
if(read.is_open())
{
while (read.good())
{
i++;
getline(read,line);
pos = line.find(_search);
if(pos != string::npos)
{
cout<<i<<": "<<line<<endl;
}
else
{
cout<<"Not found"<<endl;
}
}
read.close();
}
}
}