📄 hash_struct.cpp
字号:
// hash_struct.cpp : Definiert den Einsprungpunkt f黵 die Konsolenanwendung.
//
#include <stdio.h>
#include <stdlib.h>
#define STL_USING_STRING
#include "stl.h"
#include "hash_table.h"
/* my hash table is of type <SMyStruct> */
struct SMyStruct
{
double size;
int age;
std::string comment;
};
typedef CHashTable<struct SMyStruct> CMyStructHashT;
int main(int argc, char* argv[])
{
CMyStructHashT MyHashTable;
struct SMyStruct* pStruct = NULL;
/* add some entries */
pStruct = new SMyStruct;
if(pStruct)
{
pStruct->size = 51;
pStruct->age = 0;
pStruct->comment = "was born 13. Juli 2003 and is a beautiful little boy";
MyHashTable.AddKey("Max", pStruct);
}
pStruct = new SMyStruct;
if(pStruct)
{
pStruct->size = 168;
pStruct->age = 31;
pStruct->comment = "mother of Max and my wife (and beautiful too)";
MyHashTable.AddKey("Jasmin", pStruct);
}
pStruct = new SMyStruct;
if(pStruct)
{
pStruct->size = 183;
pStruct->age = 32;
pStruct->comment = "that's I'am";
MyHashTable.AddKey("Rex", pStruct);
}
/* get the members */
printf("THE FAMILY IS:\n\n");
CMyStructHashT::iterator iter = MyHashTable.begin();
while(iter != MyHashTable.end())
{
printf(" %s\n", iter->c_str());
iter++;
}
printf("\n\n");
/* get a special member */
printf("WHO IS \"Max\":\n\n");
pStruct = MyHashTable.GetMember("Max");
if(pStruct)
{
printf("Max is %lf cm height and %i years old.\n", pStruct->size, pStruct->age);
printf("He %s.", pStruct->comment.c_str());
}
printf("\n\n");
/* clean up the table and free allocated memory */
MyHashTable.RemoveAllKey(true);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -