错误1错误C2678:二进制'!=':找不到哪个运算符带有'std :: ofstream'类型的左操作数(或者没有可接受的转换)

0 c++ binary

我在调试或发布时遇到此错误

错误1错误C2678:二进制"!=":没有操作员发现这需要类型的左边的操作数"的std :: ofstream的"(或没有可接受的转换)C:\用户\ yuser \桌面\注射器\注射器\ 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);
}
Run Code Online (Sandbox Code Playgroud)

Woj*_*wka 5

这条线

if (ofile != NULL)
Run Code Online (Sandbox Code Playgroud)

在C++ 03中有效,但在C++ 11中无效.使用简单

if (ofile)
Run Code Online (Sandbox Code Playgroud)