⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileoperator.cpp

📁 人工智能课程设计之二
💻 CPP
字号:
// FileOperator.cpp: implementation of the CFileOperator class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Decode.h"
#include "FileOperator.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFileOperator::CFileOperator()
{

}

CFileOperator::~CFileOperator()
{

}

void CFileOperator::Path(CString &path)
{
	CString errors="Errors!";
	CString msg="File path error!";
	CFileDialog dlg(true,"TXT",NULL,NULL,"Text file(*.txt)|*.TXT|",NULL);
	if(dlg.DoModal()==IDOK)
		path=dlg.GetPathName();
	else
		MessageBox(GetFocus(),msg,errors,MB_OK);
}

bool CFileOperator::Fread(CString & txt,CString path)
{
	CFile file;
	CString errors="Errors!";
	CString errors1="Openning file error!";
	CString errors2="Reading file error!";
	if(!file.Open(path,CFile::modeRead))
	{
		MessageBox(GetFocus(),errors1,errors,MB_OK);
	    return false;
	}
	int len=file.GetLength();
	char *buffer=new char [len+1];
	try{
			file.Read(buffer,len);
	}
	catch(CFileException *e)
	{
		MessageBox(GetFocus(),errors2,errors,MB_OK);
		file.Close();
		e->Delete();
		return false;
	}
	buffer[len]='\0';
	txt+=buffer;
	return true;
}

bool CFileOperator::Fwrite(CString &txt,CString path)
{
	CFile file;
	CString errors="Errors!";
	CString errors1="Openning file error!";
	CString errors2="writing file error!";
	if(!file.Open(path,CFile::modeWrite|CFile::modeCreate))
	{
		MessageBox(GetFocus(),errors1,errors,MB_OK);
		return false;
	}
	int len=strlen(txt);
	file.Write(txt,len);
	file.Close();
	return true;
}

⌨️ 快捷键说明

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