【发布时间】:2014-08-07 19:56:09
【问题描述】:
我在调试或发布时遇到此错误
错误 1 错误 C2678: 二进制 '!=' : 未找到采用 'std::ofstream' 类型的左侧操作数的运算符(或没有可接受的转换) c:\users\yuser\desktop\injector \injector\WriteLog.h 27 1 喷油器
谁能帮我解决这个问题
代码Writelog.h
#include <windows.h>
#include <tlhelp32.h>
#include <shlwapi.h>
#include <conio.h>
#include <stdio.h>
#include <iostream>
#pragma warning(disable:4996)
using namespace std;
ofstream ofile;
char dlldir[320];
char LogFileName[20] = "Log.txt"; //Change this if you want
char *GetDirectoryFile(char *filename){
static char path[320];
strcpy(path, dlldir);
strcat(path, filename);
return path;
}
void WriteLog(const char *fmt, ...){
if (ofile != NULL) <<< Problem is here on( ! ) gives error
{
if (!fmt) { return; }
va_list va_alist;
char logbuf[256] = { 0 };
va_start(va_alist, fmt);
_vsnprintf(logbuf + strlen(logbuf), sizeof(logbuf) - strlen(logbuf), fmt, va_alist);
va_end(va_alist);
ofile << logbuf << endl;
}
}
void logstart(HMODULE hDll){
GetModuleFileName(hDll, dlldir, 512);
for (int i = strlen(dlldir); i > 0; i--) { if (dlldir[i] == '\\') { dlldir[i + 1] = 0; break; } }
ofile.open(GetDirectoryFile(LogFileName), ios::app);
}
【问题讨论】:
-
问题显然是题外话。