高分求人帮忙哦。初学c++ builder有很多不懂,眼下有个源码vc做的需转成c++ builder。希望有人指点
#ifndef _EXT_WRITELOGFILE_H
#define _EXT_WRITELOGFILE_H
#include "stdafx.h"
#include <direct.h>
CWLogFile::CWLogFile()
{
m_strPath = new char[200];
m_strFileName = new char[100];
memset(m_strPath, 0, sizeof(m_strPath));
memset(m_strFileName, 0, sizeof(m_strFileName));
//默认当前目录
char szExePath[MAX_PATH];
GetModuleFileName(NULL, szExePath, MAX_PATH);
*(strrchr(szExePath, '\\')) = '\0';
strcpy(m_strPath, szExePath);
sprintf(m_strFileName, "%s.txt", CTime::GetCurrentTime().Format("%Y-%m-%d"));
}
CWriteLogFile::~CWriteLogFile()
{
delete [] m_strPath;
delete [] m_strFileName;
}
void CWriteLogFile::SetPath(char *strPathName)
{
char *ptr = NULL;
strcpy(m_strPath, strPathName);
ptr = strrchr(m_strPath, '\\');
if(ptr != NULL)
{
*strrchr(m_strPath, '\\') = '\0';
}
}
int CWriteLogFile::WriteFile(char *strInfo,int sign)
{
char strPathName[200];
//sprintf(strPathName, "%s\\%s\\", m_strPath,
//CTime::GetCurrentTime().Format("%Y-%m-%d"));
// sprintf(strPathName, "%s\\", m_strPath); //原来
switch(sign)
{
case 1:
sprintf(strPathName, "%s\\TRW_AIRBAG_NMLOG\\", m_strPath);
break;
case 2:
sprintf(strPathName, "%s\\TRW_AIRBAG_ERLOG\\", m_strPath);
break;
default:
sprintf(strPathName, "%s\\TRW_AIRBAG_OTHLOG\\", m_strPath);
break;
}
_mkdir(strPathName);
strcat(strPathName, m_strFileName);
BOOL bExist = Open(strPathName, CFile::modeWrite);
if (!bExist)
{
BOOL bSuccess = Open(strPathName, CFile::modeCreate | CFile::modeWrite);
if (!bSuccess)
{
return 0;
}
}
SYSTEMTIME SysTime;
CString str_t;
GetLocalTime(&SysTime);
str_t.Format("%4d-%02d-%02d %02d:%02d:%02d",
SysTime.wYear,SysTime.wMonth,SysTime.wDay,SysTime.wHour,SysTime.wMinute,SysTime.wSecond);
char strWriteInfo[200];
sprintf(strWriteInfo, "[" + timestr + "] %s \r\n", strInfo);
SeekToEnd();
Write(strWriteInfo, strlen(strWriteInfo));
Close();
return 1;
}
[解决办法]
你是操作 文件用的嘛,
可以使用
<sdtio.h>
fopen
fputs
fseek
fclose
等函数
FILE *in; String fName=FormatDateTime("'.\\WeightLog\\'yyyymmdd'.txt'",Date()); String ss=""; ss=FormatDateTime("yyyy-mm-dd hh:nn:ss",Now()); ss+=" "+IntToStr(DAWDataBuf[DAWDataIndex].TotalWeight); ss+=" "+IntToStr(DAWDataBuf[DAWDataIndex].AxleCount); ss+=" "; for(int i=0;i<DAWDataBuf[DAWDataIndex].AxleGroupCount;i++) { ss+=IntToStr(DAWDataBuf[DAWDataIndex].dAxleGroupData[i].AxleGroupType); } for(int i=0;i<DAWDataBuf[DAWDataIndex].AxleGroupCount;i++) { ss+=" "+IntToStr(DAWDataBuf[DAWDataIndex].dAxleGroupData[i].AxleGroupWeight); } ss+=" "+IntToStr(DAWDataBuf[DAWDataIndex].Speed); in = fopen(fName.c_str(), "a+"); fputs(ss.c_str(),in); fputs("\n",in); fclose(in);
------解决方案--------------------