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

📄 fileoperator.cpp

📁 功能强大的网络蜘蛛软件
💻 CPP
字号:
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
#include "FileOperator.h"

FileOperator::FileOperator()
{

}

FileOperator::~FileOperator()
{

}

void FileOperator::LoadFileToStr(string &s, string filename)
{
	ifstream is(filename.c_str());
	s.erase();
	if(is.bad()) return;
	s.reserve(is.rdbuf()->in_avail());
	char c;
	while(is.get(c))
	{
		if(s.capacity() == s.size())
			s.reserve(s.capacity() * 3);
		s.append(1, c);
	}
	is.close();
}


void FileOperator::WriteToFile(string filename, string content, int mode)
{    string stime="";
	ofstream outfile;
	if(mode==0)
		outfile.open(filename.c_str());
	else
		outfile.open(filename.c_str(), ios::app);    Functions::get_time(stime);
	outfile << stime << "   " << content ;
	outfile.close();
}

void FileOperator::WriteToFile(string filename, int content, int mode)
{    string stime="";
	ofstream outfile;
	if(mode==0)
		outfile.open(filename.c_str());
	else
		outfile.open(filename.c_str(), ios::app);    Functions::get_time(stime);
	outfile << stime << "   " << content ;
	outfile.close();
}

void FileOperator::WriteToFile(string filename, const char *content, int mode)
{    string stime="";
	ofstream outfile;
	if(mode==0)
		outfile.open(filename.c_str());
	else
		outfile.open(filename.c_str(), ios::app);    Functions::get_time(stime);
	outfile << stime << "   " << content ;
	outfile.close();
}

void FileOperator::WriteToFileLn(string filename, string content, int mode)
{    string stime="";
	ofstream outfile;
	if(mode==0)
		outfile.open(filename.c_str());
	else
		outfile.open(filename.c_str(), ios::app);    Functions::get_time(stime);
	outfile << stime << "   " << content << endl;
	outfile.close();
}

void FileOperator::WriteToFileLn(string filename, int content, int mode)
{    string stime="";
	ofstream outfile;
	if(mode==0)
		outfile.open(filename.c_str());
	else
		outfile.open(filename.c_str(), ios::app);    Functions::get_time(stime);
	outfile << stime << "   " << content << endl;
	outfile.close();
}

void FileOperator::WriteToFileLn(string filename, const char *content, int mode)
{    string stime="";
	ofstream outfile;
	if(mode==0)
		outfile.open(filename.c_str());
	else
		outfile.open(filename.c_str(), ios::app);    Functions::get_time(stime);
	outfile << stime << "   " << content << endl;
	outfile.close();
}

void FileOperator::WriteLnToFile(string filename, int num=1)
{
	ofstream outfile;
	outfile.open(filename.c_str(), ios::app);
	while (num-- > 0){
		outfile << endl;
	}
	outfile.close();
}

⌨️ 快捷键说明

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