//: C04:CLibTest.cpp
//{L} CLib
// Test the C-like library
#include "CLib.h"
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
/* Define variables at the beginning of the block, as in C: */
CStash intStash, stringStash;
int i;
char* cp;
ifstream in;
string line;
const int bufsize = 80;
/* Now remember to initialize the variables: */
initialize(&intStash, sizeof(int));
for(i = 0; i < 100; i++)
add(&intStash, &i);
for(i = 0; i < count(&intStash); i++)
cout <<"fetch(&intStash,"<<i<<") = "<<*(int*)fetch(&intStash,i)<< endl;/* Restituisce l'intero associato all'indirizzo dato dalla fetch dell'elemento cercato */
/* Holds 80-character strings: */
initialize(&stringStash, sizeof(char)*bufsize);
in.open("CLibTest.cpp");
while(getline(in, line))
add(&stringStash, line.c_str());
i = 0;
while((cp = (char*)fetch(&stringStash,i++))!=0)/* Assegna alla variabile cp il puntatore */
cout << "fetch(&stringStash, " << i << ") = "<< cp << endl;
/* Nello storage all'inizio del carattere cercato */
cleanup(&intStash);
cleanup(&stringStash);} ///:~