测试代码
字典.h
#ifndef 字典_H_
#define 字典_H_
#include <string>
using namespace std;
// 字典定义
typedef struct Node
{
string cipherText; // 密文
string lightText; // 明文
} node;
// 字典集合
typedef struct List
{
node item;
List *nextItem;
} list;
class Diction
{
private:
list * dicList; // 一本字典
int top; // 字典长度
public:
Diction();
void readLine();
void creatList();
void showList();
void freeList();
void findWord(string str);
};
#endif
字典.cpp
#include <iostream>
#include <fstream>
#include <cstdlib>
#include "字典.h"
Diction::Diction()
{
dicList = NULL;
}
void Diction::readLine()
{
ifstream inFile;
inFile.open(".\\Dic.txt", ios::in);
if (!inFile.good())
{
cout << "无法打开数据文件.\n";
exit(1);
}
int line = 0;
string temp;
// 定位到流头部
inFile.seekg(0, ios::beg);
while (getline(inFile, temp))
{
++line;
}
//