Hello All,
I currently am writing a program that creates recipe text files. I have a folder on my desktop to hold the files. My program asks the the user to name the recipe using the std::getline function. I want to use that variable to name the file at a certain path. Here is my code:
Code:#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
std::string name, category, group, style, prep, ingred, instruct, notes;
char answer;
//Recipe information questions:
std::cout<<"Recipe name?\n\n";
std::getline ( std::cin, name );
ofstream recipe("C:\\Users\\Tony\\Desktop\\magic cookbook\\",name); //names the recipe file
std::cout<<"\n\nCategory?\n\n";
std::getline ( std::cin, category );
recipe << "Recipe Category: ";
recipe << category;
std::cout<<"\n\nFood Group?\n\n";
std::getline ( std::cin, group );
std::cout<<"\n\nFood Style?\n\n";
std::getline ( std::cin, style );
std::cout<<"\n\nPrep Time?\n\n";
std::getline ( std::cin, prep);
std::cout<<"\n\nRecipe Ingredients?\n\n";
std::getline ( std::cin, ingred );
std::cout<<"\n\nCooking Instructions?\n\n";
std::getline ( std::cin, instruct );
std::cout<<"\n\nServing Notes?\n\n";
std::getline ( std::cin, notes );
//outputing the recipe
cout<<"\n\nView Recipe? y/n?\n\n";
cin>> answer;
if (answer == 'y')
{
std::cout<<"\n\n" << name <<"\n\n";
std::cout<<"Category: "<< category <<"\n\n";
std::cout<<"Food Group: "<< group <<"\n\n";
std::cout<<"Food Style: "<< style <<"\n\n";
std::cout<<"Prep Time: "<< prep <<"\n\n";
std::cout<<"Ingredients: "<< ingred <<"\n\n";
std::cout<<"Cooking Instructions: "<< instruct <<"\n\n";
std::cout<<"Serving Notes: "<< notes <<"\n\n";
}
}
Here are my errors:
C:\Users\Tony\Desktop\magic cookbook\magic2\main.cpp|16|error: no matching function for call to `std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(const char[38], std::string&)'|
I'm modifying the last program that I made just to display the input that the user gave.
Eventually I want to program to gather all the input and save it as a file.
How do I use that path for the file and add the variable name at the end?
Thanks,
Tony