-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcategories.cpp
More file actions
46 lines (36 loc) · 740 Bytes
/
categories.cpp
File metadata and controls
46 lines (36 loc) · 740 Bytes
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
#include "categories.h"
Categories::Categories(char *fileName)
{
m_fileName = fileName;
buffer.clear();
updateBuffer();
}
Categories::~Categories()
{
}
void Categories::saveBuffer()
{
m_file = fopen(m_fileName,"wb");
for(iter = buffer.begin(); iter != buffer.end(); iter++)
{
categories prod = *iter;
fwrite(&prod,sizeof(prod),1,m_file);
}
buffer.clear();
fclose(m_file);
}
void Categories::updateBuffer()
{
buffer.clear();
m_file = fopen(m_fileName,"rb");
if(m_file == NULL)
{
return;
}
categories *prod = new categories;
while(fread(prod,sizeof(categories),1,m_file) == 1)
{
buffer.push_back(*prod);
}
fclose(m_file);
}