Hi,
Can anyone help me with this problem.For example i have a text file called food.txt with contents
1 apples
2 oranges
3 mango
4 bananna
What i would like to do is enter the choice of fruit into a string and loop through the file until the word is found.My problem being i dont fully understand any of the examples online and would be grateful if someone could point me in the right direction.
Here is my code so far
main(){
char filename[size];
char line[size];
string fruit;
cout << "Please enter filename: ";
cin >> filename;
cout << "enter fruit:" << endl;
cin >> fruit;
cout << fruit;
cout << "\n Filename is: " << filename << endl;
cout << "Opening file.." << endl;
fstream* file = new fstream(filename,fstream::in);
while(file->getline(line,size) != NULL)
{
cout << line;
// if the line is the same as fruit entered print out the line(this does not work!)
if(line == fruit)
{
cout << line;
}
}
system("PAUSE");
}