Inventory System, getting a few errors

Hi, I'm rather new to programming and I'm working on an inventory management system for the class I'm in. Here are the directions for the assignment:

Your code need to have the following features, all accessible from a menu.

Add an inventory item to the data file. This will automatically sort the data too. (Insertion sort is the one you want, see the code in the folder to do this). This will update the number of items on the menu screen.
Search the inventory for an item by inventory number. This assumes the array is sorted (which it should be) and uses a binary search. If found, print the stored info, otherwise print 'not found'.
List the inventory on the screen in neat columns. Display it in chucks of 15 items with a pause in between.
Save the inventory to the datafile. It should also stay in memory. You can 'hardcode' the name of the file, as opposed to asking for it, that way it's always the same.

Here's what I have came up with so far, and the error that is coming up is "no matching function call to std::vector<std::basic_string...." at line 114.

Any help would be appreciated :)

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    void listInventory (ofstream& myFile2, string inventoryArray[], int sizeArray[]);

    int choice;
    string fileName;
    ifstream myFile;
    ofstream myFile2;

    int invNumS;
    vector<string> inventoryDescription;
    vector<string> inventoryNumber;

    vector<string>::const_iterator it;

    string description;
    string number;
    int size = 0;
    double price;
    int quantity;



    while(choice != 0)
    {

        cout << endl;
        cout << "To use the menu, please enter one of the numbers: " << endl << endl;
        cout << "1) Load" << endl;
        cout << "2) Add" << endl;
        cout << "3) Search" << endl;
        cout << "4) List" << endl;
        cout << "5) Save" << endl << endl;
        cout << "0) Exit" << endl << endl;
        cout << "Choose a menu option: ";
        cin >> choice;

        switch(choice)
        {

            {
            case 1:

                cout << "What is the name of the file you would like to open?  ";
                cin >> fileName;
                cout << endl;

                myFile.open(fileName.c_str());

                if (myFile.fail())
                {
                    cerr << "Open failed";
                    exit(1);
                }
                else
                {
                    cout << "\nFile has sucessfully loaded, you may now return to the menu." << endl << endl;
                }

                break;
            }

        case 2: // Add

        {
            myFile2.open(fileName.c_str());

            cout << "Enter inventory number for new data: ";
            cin.ignore();
            getline(cin, number);

            inventoryNumber.push_back(number);
            sort(inventoryNumber.begin(), inventoryNumber.end());

            cout << "Enter an item description: ";
            cin.ignore();
            getline(cin, description);

            inventoryDescription.push_back(description);
            sort(inventoryDescription.begin(), inventoryDescription.end());

            cout << "\nEnter the quantity of products in stock: ";
            cin >> quantity;

            cout << "Enter an item price: ";
            cin >> price;

            myFile2 << number << endl;
            myFile2 << description << endl;
            myFile2 << quantity << endl;
            myFile2 << price << endl;
            int invNumS;

            myFile2.close();
            break;
        }
        case 3:

            int invNumS;

            cout << "Enter the inventory number of the item to search: ";
            cin>> invNumS;


            for (int i = 0; i != inventoryNumber.end(it); i++)
                if (invNumS == inventoryNumber)
                {
                    cout << endl << "Data for item number " << invNumS << ":" << endl << endl;
                    cout << "Item description is: " << inventoryDescription << endl;
                    cout << "There are " << quantity << " in stock and the price is " << price << endl;
                }

                else
                {
                    cout << "There is no item number " << invNumS;
                }

            break;

        }

    //case 4: //List
    //case 5: // Save





}

return (0);

}
You can iteretate a vector like this:
for (int i = 0; i != inventoryNumber.end(it); i++)

Two example of how:
1
2
3
for (vector<string>::iterator i = inventoryNumber.begin();
 i != inventoryNumber.end();
 i++)


or:
1
2
3
for (int i = 0;
 i < inventoryNumber.size();
 i++)
Last edited on
Thanks, I made a few changes so now it will compile, but the program itself isn't working as it should. Did you by chance notice any logic errors I made earlier in the program as far as loading and sending the information to the data file goes?

Here are the changes I made also,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 int invNumS;

            cout << "Enter the inventory number of the item to search: ";
            cin>> invNumS;

            for (vector<string>::iterator i = inventoryNumber.begin(); i != inventoryNumber.end(); i++)
               {
                    if (invNumS == inventoryNumber.size())
                {
                    cout << endl << "Data for item number " << invNumS << ":" << endl << endl;
                    cout << "Item description is: " << inventoryDescription.size() << endl;
                    cout << "There are " << quantity << " in stock and the price is " << price << endl;
                }

                else
                {
                    cout << "There is no item number " << invNumS;
                }
               }

            break;

Thanks!
Topic archived. No new replies allowed.