-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.cpp
More file actions
48 lines (42 loc) · 1.06 KB
/
database.cpp
File metadata and controls
48 lines (42 loc) · 1.06 KB
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
#include <iostream>
#include <vector>
#include <string>
#include <climits>
struct Data
{
std::string description;
int item;
};
int main()
{
bool flag = false;
int pos = 0;
std::string key;
Data obj;
std::vector<Data> list;
std::cout << "Please enter the name of each item followed by the number of such item." << std::endl;
while(getline(std::cin, obj.description) && std::cin>>obj.item)
{
std::cin.clear();
std::cin.ignore(INT_MAX, '\n');
list.push_back(obj);
}
std::cout<<"Enter the description of the item you want to delete."<<std::endl;
std::cin.clear();
// std::cin.ignore(INT_MAX, '\n');
getline(std::cin, key);
// std::cout << key << std::endl;
for(auto start = list.begin() ; start != list.end() ; ++start)
{
if((*start).description == key)
{
flag = true;
list.erase(list.begin() + pos);
}
++pos;
}
if(flag == false)
std::cout <<"Item not found!"<<std::endl;
for(auto start = list.begin() ; start != list.end() ; ++start)
std::cout << "Item Name: " << (*start).description << " Count: " << (*start).item << std::endl;
}