-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcLibTest.cpp
More file actions
43 lines (40 loc) · 1.02 KB
/
Copy pathcLibTest.cpp
File metadata and controls
43 lines (40 loc) · 1.02 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
//: C04:cLibTest.cpp
//{L} cLib
//Test the C-Like Library
#include <iostream>
#include <fstream>
#include "cLib.h"
#include <string>
#include <cassert>
int main (int argc, char** argv) {
cStash intStash, stringStash;
int i;
char* cp;
std::ifstream in;
std::string line;
int a;
const int bufsize = 80;
initialize(&intStash, sizeof(int));
for (i = 0; i < 100; i++) {
add(&intStash, &i);
}
for (i = 0; i < count(&intStash); i++) {
std::cout << "fetch(&intStash, " << i << ") ="
<< *(int*)fetch(&intStash, i)
<< std::endl;
}
std::cout << " --------------------------------------------------------------------------------------" << std::endl;
initialize(&stringStash, sizeof(char)* bufsize);
in.open("CLibTest.cpp");
assert(in);
while (getline(in, line))
add(&stringStash, line.c_str());
i = 0;
while ((cp = (char*)fetch(&stringStash, i++)) != 0) {
std::cout << "fetch(&stringStash, " << i << ") ="
<< cp << std::endl;
std::cout << "*cp : " << *cp << std::endl;
}
cleanup(&intStash);
cleanup(&stringStash);
}