Hi all, any help would be greatly appreciated. This program is supposed to allow the user to read in a txt file with ingredients for recipes. We were asked to use the fstream and to use functions to read in the info and display it. I am new to this and have the following error message I can't figure out..
I don't know how to add numbers to the left of the code but the red marked line is at line 54 which begins the function that has the errors in it.
Any help would be greatly appreciated!!
~G

lines 64,76,78,89, 95,96
no matching function for call to getline(std::basic_ifstream<char, std::char_traits<char> >double&)
same msg for lines 80, 97 only replace double with bool

CODE

#include<iostream>
#include<fstream>
#include<string>

using namespace std;

//////////////
//struct
/////////////
struct Recipe
{
        string recipeName;
        double page;
        string meatIngred;
        string ingred2;
        string ingred3;
        string ingred4;
        string ingred5;
        double tempature;
        double time;
        bool   isEasy;
};
////////////////////////////
// prototype
///////////////////////////
void fillIngred(Recipe[], int, ifstream&);
//void displayIngred(Recipe, int);



int main()
{
        ifstream indata;

        //CONSTANTS;
        const int MAX = 10;

        //VARIABLES
        Recipe book[MAX];


        indata.open("recipeFile.txt");

        if(!indata)
        {
                cerr << "Error: File could not be opened" << endl;
        }


        fillIngred(book, MAX, indata);

        displayIngred(book);
        indata.close();
}
[COLOR="Red"]void fillIngred(Recipe temp[], int MAX, ifstream& indata)[/COLOR]
{
                cout<<"entering data...: ";
                getline(cin, temp[num].recipeName);
                getline(indata, temp[num].page);
                getline(indata, temp[num].meatIngred);
                getline(indata, temp[num].ingred2);
                getline(indata, temp[num].ingred3);
                getline(indata, temp[num].ingred4);
                getline(indata, temp[num].ingred5);
                getline(indata, temp[num].tempature);
                getline(indata, temp[num].time);
                getline(indata, temp[num].isEasy);

        }
        while (!indata.eof());
        {
            for (int i=0; i<MAX; i++)
            {
                num++;
                getline(indata, temp[num].recipeName);
                getline(indata, temp[num].page);
                getline(indata, temp[num].meatIngred);
                getline(indata, temp[num].ingred2);
                getline(indata, temp[num].ingred3);
                getline(indata, temp[num].ingred4);
                getline(indata, temp[num].ingred5);
                getline(indata, temp[num].tempature);
                getline(indata, temp[num].time);
                getline(indata, temp[num].isEasy);

            }
        }
}

void displayIngred(Recipe temp[], int MAX)
{
     for (int i=0; i<MAX; i++)
     {
        cout << temp[i].recipeName << endl;
        cout << temp[i].page << endl;
        cout << temp[i].meatIngred << endl;
        cout << temp[i].ingred2 << endl;
        cout << temp[i].ingred3 << endl;
        cout << temp[i].ingred4 << endl;
        cout << temp[i].ingred5 << endl;
        cout << temp[i].tempature << endl;
        cout << temp[i].time << endl;
        cout << temp[i].isEasy << endl;
        cout << endl;
        cout << endl;
      }
}

Recommended Answers

All 2 Replies

getline(indata, temp[num].time);

See that value, temp[num].time? That's a double. The getline function doesn't know what to do with it. It only knows what to do with strings.

temp[num].isEasy - that's a bool. The getline function doesn't know what to do with it. It only knows what to do with strings.

Likewise with all the others. getline only knows what to do with a string as the second parameter.

Thank you so much for your help with that! I was working at it for hours and I couldn't figure out what the problem was. That fixed all the error messages. Now I just need to figure out why it gets stuck when I run it! Wish me luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.