暂时封装一个文件输出类,平时要用的时候方便一些
#include <stdio.h>
#include <string>
using namespace std;
class fileopr
{
string m_filepath;
FILE *m_pFile;
public:
fileopr()
{
m_filepath = "d:\\test.txt";
#ifdef VS_2013
fopen_s(&m_pFile, m_filepath.c_str(), "ab+");
#else
m_pFile = fopen(m_filepath.c_str(), "ab+");
#endif
}
fileopr(string filepath)
{
m_filepath = filepath;
#ifdef VS_2013
fopen_s(&m_pFile, m_filepath.c_str(), "ab+");
#else
m_pFile = fopen(m_filepath.c_str(), "ab+");
#endif
}
~fileopr()
{
fclose(m_pFile);
}
void changefilepath(const string &filepath)
{
m_filepath = filepath;
//重连
fclose(m_pFile);
#ifdef VS_2013
fopen_s(&m_pFile, m_filepath.c_str(), "ab+");
#else
m_pFile = fopen(m_filepath.c_str(), "ab+");
#endif
}
void outputInt(int Value)
{
fprintf(m_pFile, "%d", Value);
}
void outputChar(char Value)
{
fprintf(m_pFile, "%c", Value);
}
void outputString(string strOutput)
{
fprintf(m_pFile, "%s", strOutput.c_str());
}
};