cin.getline error message

My program is designed to read input from the user and then store that input in a structure variable. Whenever i use the cin.getline() function, it comes up with a semantic issue. Here is the code:
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

const int DESCRIPTION_SIZE = 100, DATE_SIZE = 20;

struct inventory
{
    string description[DESCRIPTION_SIZE];
    int quantity;
    double wholeCost;
    double retailCost;
    string dateAdded[DATE_SIZE];
};

int displayFile(fstream &);
long byteNum(int);
void displayRecord(inventory);
int addToFile(fstream &);
int changeFile(fstream &);
void quitChoice();

int main(int argc, const char * argv[])
{
    fstream inventoryFile("inverntoryData.txt", ios::in | ios::binary);
    int choice;
    cout << "This program allows you to look at our inventory." << endl;
    cout << "Chose the option you want: \n";
    cout << "1.Add new records. \n2.Display any record.\n3.Change any record.\n4.Quit" << endl;
    cin >> choice;
    
    do
    {
        switch (choice)
        {
            case 1: addToFile(inventoryFile);
                break;
            case 2: displayFile(inventoryFile);
                break;
            case 3: changeFile(inventoryFile);
                break;
            case 4: quitChoice();
                return 0;
        }
        
        cout << "Chose the option you want: \n";
        cout << "1.Add new records. \n2.Display any record.\n3.Change any record.\n4.Quit";
        cin >> choice;
    } while (choice != 4);
    
    return 0;
}
int addToFile(fstream &file)
{
    inventory adding;
    if (!file)
    {
        cout << "Error opening file.";
        return 0;
    }
    
    cout << "Enter the description of the inventory: ";
    cin.getline(adding.description, DESCRIPTION_SIZE);
    cout << "Enter the quantity: ";
    cin >> adding.quantity;
    cin.ignore();
    cout << "Enter the wholesale cost: ";
    cin >> adding.wholeCost;
    cin.ignore();
    cout << "Enter the retail cost: ";
    cin >> adding.retailCost;
    cin.ignore();
    cout << "Enter the date added to inventory: ";
    cin.getline(adding.dateAdded, DATE_SIZE);
}


I left out the other functions. The error reads "no matching member function for call to 'getline'. How can i fix this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// ...

struct inventory
{
    string description[DESCRIPTION_SIZE];
    int quantity;
    double wholeCost;
    double retailCost;
    string dateAdded[DATE_SIZE];
};

// ...

    cout << "Enter the description of the inventory: ";
    getline(cin, adding.description);
    cin.getline(adding.description, DESCRIPTION_SIZE);

// ...
    cout << "Enter the date added to inventory: ";
    getline(cin, adding.dateAdded);
    cin.getline(adding.dateAdded, DATE_SIZE);

// ... 


Ok, so i tried that, and it didn't change anything except now it says no matching function for call to geline.
I'm using Xcode for mac. Does this have anything to do with it?
Ok, so i tried that, and it didn't change anything except now it says no matching function for call to geline.

I'm using Xcode for mac. Does this have anything to do with it?


No, that has nothing to do with it. If the changes I suggested were the only changes you made, this shouldn't be a problem.
My textbook has the exact same syntax as i do, yet it still says there is a semantic error.
Your textbook is not using arrays of std::string.
Topic archived. No new replies allowed.