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

📄 io.cpp

📁 最大子矩阵和问题
💻 CPP
字号:
// IO.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream.h>
#include <fstream.h>
#include <string.h>

class OutPut
{
private:
	ofstream ofile;
public:
	OutPut(char *path)
	{
		ofile.open(path);
		if(!ofile.is_open())
		{
			throw "file cann't be opened";
		}
	}

	~OutPut()
	{
		if(ofile.is_open())
		{
			ofile.close();
		}
	}

	void Close()
	{
		if(ofile.is_open())
		{
			ofile.close();
		}
	}

	ofstream& operator <<(int i)
	{
		ofile<<i;
		return ofile;
	}

	ofstream& operator <<(char* str)
	{
		ofile<<str;
		return ofile;
	}

	ofstream& operator <<(char c)
	{
		ofile<<c;
		return ofile;
	}

	ofstream& operator <<(double i)
	{
		ofile<<i;
		return ofile;
	}

	ofstream& operator <<(float i)
	{
		ofile<<i;
		return ofile;
	}
};

class InPut
{
private:
	ifstream ifile;
public:
	InPut(char* path)
	{
		ifile.open(path);
		if(!ifile.is_open())
		{
			throw "file cann't be opened";
		}
	}

	~InPut()
	{
		if(ifile.is_open())
		{
			ifile.close();
		}
	}

	void Close()
	{
		if(ifile.is_open())
		{
			ifile.close();
		}
	}

	ifstream& operator >>(int &i)
	{
		ifile>>i;
		return ifile;
	}

	ifstream& operator >>(char &c)
	{
		char ch=0;
		while(ch<32||ch>127)
		{
			ifile>>ch;
		}
		c=ch;
		return ifile;
	}

	ifstream& operator >>(char *str)
	{
		//ifile.getline(str,sizeof(str));
		ifile>>str;
		return ifile;
	}

	ifstream& operator >>(double &i)
	{
		ifile>>i;
		return ifile;
	}

	ifstream& operator >>(float &i)
	{
		ifile>>i;
		return ifile;
	}
};

class Tool
{
public:
	ifstream ifile1;
	ifstream ifile2;
	char path1[100];
	char path2[100];

public:
	Tool(char* _path1,char* _path2)
	{
		ifile1.open(_path1);
		ifile2.open(_path2);
		if(!ifile1.good()||!ifile2.good())
		{
			throw "file cann't be opened";
		}
		strcpy(path1,_path1);
		strcpy(path2,_path2);
	}

	~Tool()
	{
		if(ifile1.is_open())
		{
			ifile1.close();
		}
		if(ifile2.is_open())
		{
			ifile2.close();
		}
	}

	void Close()
	{
		if(ifile1.is_open())
		{
			ifile1.close();
		}
		if(ifile2.is_open())
		{
			ifile1.close();
		}
	}

	bool Compare()
	{
		if(!ifile1||!ifile2)
		{
			::cout<<"open error"<<endl;
			return false;
		}
		char str1[100];
		char str2[100];
		int line=0;
		while(ifile1.good()&&ifile2.good())
		{
			ifile1.getline(str1,sizeof(str1));
			ifile2.getline(str2,sizeof(str2));
			if(strcmp(str1,str2)!=0)
			{
				::cout<<"different:"<<path1<<":"<<line<<endl;
				return false;
			}
			line++;
		}
		if(ifile1.good()&&!ifile2.good())
		{
			::cout<<"different:"<<path1<<":"<<line<<endl;
			return false;
		}
		else if(!ifile1.good()&&ifile2.good())
		{
			::cout<<"different:"<<path1<<":"<<line<<endl;
			return false;
		}
		/*else
		{
			::cout<<"same"<<endl;
			return false;
		}*/
		return true;
	}
};

⌨️ 快捷键说明

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