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

📄 savetofile.cpp

📁 关于字符分割的程序
💻 CPP
字号:
// savetofile.cpp: implementation of the savetofile class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "hwpre.h"
#include "savetofile.h"

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

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

savetofile::savetofile()
{

}

savetofile::~savetofile()
{

}

BOOL savetofile::filesave(int * iarray, int lWidth, int lHeight)
{
	int i,j;
	char lpszPathName[255];
	getFileName(lpszPathName);

	CFile file;
	CFileException fe;
	CString str1; char str2[2];
	str2[0]=13;str2[1] =10;
	if (!file.Open(lpszPathName,CFile::modeCreate|CFile::modeReadWrite|CFile::shareExclusive,&fe)) {
		//ReportSaveLoadException(lpszPathName,&fe,TRUE,AFX_IDP_INVALID_FILENAME);
	//	return FALSE;
	}
	BOOL bSuccess = FALSE;
	TRY{
//		BeginWaitCursor();
		for (i=0;i<lHeight;i++) {
			for (j=0;j<lWidth;j++) {
				if (j==0) {
					str1.Format("%d",iarray[i*lWidth+j]);
				}else
				{
					str1.Format("\t%d",iarray[i*lWidth+j]);
				}
				
				file.Write(str1,str1.GetLength());
			}
			file.Write(str2,2);
		}
		file.Close();
		bSuccess =TRUE;
	}
	CATCH(CException,eSave){
		file.Abort();
//		EndWaitCursor();
//		ReportSaveLoadException(lpszPathName, eSave,TRUE, AFX_IDP_FAILED_TO_SAVE_DOC);
	//	return FALSE;
	}
	END_CATCH
//	EndWaitCursor();
//	SetModifiedFlag(FALSE);
	
	if (!bSuccess) {
		CString strMsg;
		strMsg=("保存失败");
		MessageBox(NULL, strMsg, NULL, MB_ICONINFORMATION | MB_OK);
		return FALSE;
	}
	return TRUE;

  }

BOOL savetofile::getFileName(LPSTR lpszPathName)
{
	CString strOpenFilter = "";
	CFileDialog FileDlg(FALSE,"txt",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,strOpenFilter);
	if (IDOK== FileDlg.DoModal()) {
		
//		lpszPathName =(FileDlg.m_ofn.lpstrFile);
		strcpy(lpszPathName,FileDlg.m_ofn.lpstrFile);
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

BOOL savetofile::filesave(double *iarray, int lWidth, int lHeight)
{
	int i,j;
	char lpszPathName[255];
	getFileName(lpszPathName);

	CFile file;
	CFileException fe;
	CString str1; char str2[2];
	str2[0]=13;str2[1] =10;
	if (!file.Open(lpszPathName,CFile::modeCreate|CFile::modeReadWrite|CFile::shareExclusive,&fe)) {
		//ReportSaveLoadException(lpszPathName,&fe,TRUE,AFX_IDP_INVALID_FILENAME);
	//	return FALSE;
	}
	BOOL bSuccess = FALSE;
	TRY{
//		BeginWaitCursor();
		for (i=0;i<lHeight;i++) {
			for (j=0;j<lWidth;j++) {
				if (j==0) {
					str1.Format("%f",iarray[i*lWidth+j]);
				}else
				{
					str1.Format("\t%f",iarray[i*lWidth+j]);
				}
				
				file.Write(str1,str1.GetLength());
			}
			file.Write(str2,2);
		}
		file.Close();
		bSuccess =TRUE;
	}
	CATCH(CException,eSave){
		file.Abort();
//		EndWaitCursor();
//		ReportSaveLoadException(lpszPathName, eSave,TRUE, AFX_IDP_FAILED_TO_SAVE_DOC);
	//	return FALSE;
	}
	END_CATCH
//	EndWaitCursor();
//	SetModifiedFlag(FALSE);
	
	if (!bSuccess) {
		CString strMsg;
		strMsg=("保存失败");
		MessageBox(NULL, strMsg, NULL, MB_ICONINFORMATION | MB_OK);
		return FALSE;
	}
	return TRUE;

}

BOOL savetofile::filesave(complex<double> *iarray, int lWidth, int lHeight)
{
	int i,j;
	char lpszPathName[255];
	getFileName(lpszPathName);

	CFile file;
	CFileException fe;
	CString str1; char str2[2];
	str2[0]=13;str2[1] =10;
	if (!file.Open(lpszPathName,CFile::modeCreate|CFile::modeReadWrite|CFile::shareExclusive,&fe)) {
		//ReportSaveLoadException(lpszPathName,&fe,TRUE,AFX_IDP_INVALID_FILENAME);
	//	return FALSE;
	}
	BOOL bSuccess = FALSE;
	TRY{
//		BeginWaitCursor();
		for (i=0;i<lHeight;i++) {
			for (j=0;j<lWidth;j++) {
				if (j==0) {
					str1.Format("=complex(%f,%f)",iarray[i*lWidth+j].real(),iarray[i*lWidth+j].imag());
				}else
				{
					str1.Format("\t=complex(%f,%f)",iarray[i*lWidth+j].real(),iarray[i*lWidth+j].imag());
				}
				
				file.Write(str1,str1.GetLength());
			}
			file.Write(str2,2);
		}
		file.Close();
		bSuccess =TRUE;
	}
	CATCH(CException,eSave){
		file.Abort();
//		EndWaitCursor();
//		ReportSaveLoadException(lpszPathName, eSave,TRUE, AFX_IDP_FAILED_TO_SAVE_DOC);
	//	return FALSE;
	}
	END_CATCH
//	EndWaitCursor();
//	SetModifiedFlag(FALSE);
	
	if (!bSuccess) {
		CString strMsg;
		strMsg=("保存失败");
		MessageBox(NULL, strMsg, NULL, MB_ICONINFORMATION | MB_OK);
		return FALSE;
	}
	return TRUE;

}

⌨️ 快捷键说明

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