dictionary1.cpp

来自「这是一个实现英汉字典的基本操作的代码。功能有:查询」· C++ 代码 · 共 69 行

CPP
69
字号
#include<fstream.h>
#include"dictionary1.h"

Dictionary1::Dictionary1()
{
	return;
}

Dictionary1::~Dictionary1()
{
	return;
}

void Dictionary1::save(ofstream& out)     //重新保存全部记录
{
	int loop;
	for(loop=0;loop<num;loop++)
		out<<(danci+loop)->English<<" "<<(danci+loop)->cixing<<" "<<(danci+loop)->Chinese<<endl;
	return;
}

int Dictionary1::Add()        //在文件尾追加一条记录,保存成功返回1,否则返回0           
{
	ofstream output_file;
	output_file.open("dic_file.txt",ios::app);     
	if(!output_file)
	{
		cout<<"文件无法打开!"<<endl;
		return 0; 
	}
    output_file<<(danci+num-1)->English<<" "<<(danci+num-1)->cixing<<" "<<(danci+num-1)->Chinese<<endl;
    output_file.close();
	cout<<"保存成功!"<<endl;
	return 1;
}

int Dictionary1::Delete()        //删除文件中一条记录,删除成功返回1,否则返回0          
{
	ofstream output_file;
	output_file.open("dic_file.txt");
	if(!output_file)
	{
		cout<<"文件无法打开!"<<endl;
		return 0; 
	}
	save(output_file);
	output_file.close();
	cout<<"保存成功!"<<endl;
	return 1;
}

int Dictionary1::Update()           //修改文件中一条记录,修改成功返回1,否则返回0
{
	ofstream output_file;
	output_file.open("dic_file.txt");
	if(!output_file)
	{
		cout<<"文件无法打开!"<<endl;
		return 0; 
	}
	save(output_file);
	output_file.close();
	cout<<"保存成功!"<<endl;
	return 1;
}
	


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?