outfile.cpp

来自「用VC++实现的关于会议室使用计划 例程解析!」· C++ 代码 · 共 52 行

CPP
52
字号
// OutFile.cpp: implementation of the OutFile class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Mplan.h"
#include "OutFile.h"

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

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

OutFile::OutFile( )	{	
	fp = NULL;		//  未打开时
}

OutFile::~OutFile( )	{	
	if( fp != NULL )	Close( );	//  先关闭		
}

int OutFile::Open( char nam[ ] )	{
	if( fp == NULL )			//  未打开时
		fp = fopen( nam,"w");	//  打开
	return fp != NULL;	//  成功否?
}

void OutFile::Close( )	{
	if( fp != NULL )		fclose( fp );
	fp = NULL;			//  关闭后
}

//  响应具有不同属性的 Write 消息
int  OutFile::Write( int v )	{
	if( fp == NULL )	return 0;
	return fprintf(fp, "%d\t", v) >= 0;
}				// 出错时,返回 0
int  OutFile::Write( double v )	{
	if( fp == NULL )	return 0;
	return fprintf(fp, "%lf\n", v) >= 0;
}
int  OutFile::Write( char s[ ] )	{
	if( fp == NULL )	return 0;
	return fprintf(fp, "%s\t", s) >= 0;
}				// 用返回值表示出错信息
				// 出错信息不输出到 cout

⌨️ 快捷键说明

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