📄 infile.cpp
字号:
// InFile.cpp: implementation of the InFile class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Mplan.h"
#include "InFile.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
InFile::InFile( ) {
fp = NULL; // 未打开时
}
InFile::~InFile( ) {
if( fp != NULL ) Close( ); // 先关闭
}
int InFile::Open( char nam[ ] ) {
if( fp == NULL ) // 未打开时
fp = fopen( nam,"r+"); // 打开
// fseek( fp, 0L, SEEK_SET );
return fp != NULL; // 成功否?
}
void InFile::Close( ) {
if( fp != NULL ) fclose( fp );
fp = NULL; // 关闭后
}
// 响应具有不同属性的 Read 消息
int InFile::Read( int &v ) {
if( fp == NULL ) return 0;
return fscanf(fp, "%d", &v) >=0;
} // 出错时,返回 0
int InFile::Read( double &v ) {
if( fp == NULL ) return 0;
return fscanf(fp, "%lf", &v) >=0;
}
int InFile::Read( char s[ ] ) {
if( fp == NULL ) return 0;
return fscanf(fp, "%s", s) >=0;
} // 用返回值表示出错信息
// 出错信息不输出到 cout
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -