Search Function with Two String Vectors

Im trying to create a searchable database, where it takes in 5 ingredients from the user as a string vector, then compares it to recipes from a text file. The textfile is converted to a string, then broken up into tokens into a string vector. When I try to search the ingredients through the tokens, it outputs every single recipe, even if the searched item is not in the recipe.

I checked and the tokenize function works perfectly

I also want to make sure that the loop will check through an ingredient in EVERY recipe (not just stop once its seen one) any tips on how to do that?


I'm very new to C++, so I appreciate any help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
    void recipesearch(const vector<string>& ingredientlist) //ifstream& recipes)
    {

	ifstream myrecipes;
	string ingredient;
	string file;
	vector <string> tokens;
	myrecipes.open("recipes.txt");
	if (myrecipes.is_open())
	{
		// read entire file into string
		myrecipes.seekg(0, std::ios::end);
		file.reserve(myrecipes.tellg());
		myrecipes.seekg(0, std::ios::beg);

		file.assign((std::istreambuf_iterator<char>(myrecipes)),
			std::istreambuf_iterator<char>());

		transform(file.begin(), file.end(), file.begin(), ::tolower);//makes database lowercase			
		Tokenize(file, tokens, "#");//places recipes as seperate strings into vector


		for (const string & ingredient : ingredientlist) // each ingredient in ingredient vector
		{
			for (const string & recipe : tokens){ //each recipe in recipe vector
				if (recipe.find(ingredient) != recipe.npos) // found ingredient in file
				{
					cout << "yo";
				}
			}
		}
		}
	else cout << "Unable to open recipe file!";
	
	myrecipes.close();

    }
Please post a small sample of your input file.
_ #

*Cheese-y Ramen*

Prep Time: 5 minutes
Cook Time: 20 minutes
Total Time: 25 minutes
Servings: 2
Ingredients:
8 oz cheddar cheese
1 tablespoon cornstarch
¾ cup milk
2 packages ramen noodles
Directions:
1. Grate cheddar cheese and add with cornstarch into a small bowl
2. Combine with milk in a medium saucepan and cook on medium to low heat until consistent. Keep warm until serving.
3. In a separate pan boil ramen noodles. Set aside the included flavor packets.
4. Once boiling, drain the noodles and combine with cheese.
Recipe from Buzzfeed
__ #
Topic archived. No new replies allowed.