Repository navigation
Expand file tree
/
Copy pathtest.cpp
More file actions
87 lines (75 loc) · 1.48 KB
/
Copy pathtest.cpp
File metadata and controls
87 lines (75 loc) · 1.48 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
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
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
void printVector(vector<unsigned char> v)
{
for(int i=0; i<v.size(); i++)
{
cout << (int)v[i] << " ";
}
cout << endl;
}
class TestDB
{
public:
vector <unsigned char> d1;
vector <unsigned char> d2;
vector<vector <unsigned char>> c;
public:
TestDB(int len)
{
for(int i=0; i<len; i++)
{
if (int(i/16) == 0)
{
d1.push_back(i);
}
else if(int(i/16) == 1)
{
d2.push_back(i);
}
}
c.push_back(d1);
c.push_back(d2);
}
void json_output()
{
ofstream ofs("test.json", ios::out);
if (ofs.is_open() == false)
{
cout << "not open" << endl;
}
else
{
cout << "open" << endl;
}
cout << "test: print the vector" << endl;
printVector(d1);
printVector(d2);
ofs << "{ ";
for(int i=0; i<c.size(); i++)
{
ofs << "\"v";
ofs << i;
ofs << "\":[";
int j;
for(j=0; j<c[i].size() - 1; j++)
{
ofs << (int)c[i][j] << ", ";
}
ofs << (int)c[i][j] << "], " << endl;
}
ofs << "}";
ofs.close();
}
};
void test()
{
TestDB t(32);
t.json_output();
}
int main()
{
test();
}