【问题标题】:Error 1 error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::ofstream' (or there is no acceptable conversion)错误 1 ​​错误 C2678:二进制“!=”:未找到采用“std::ofstream”类型的左侧操作数的运算符(或没有可接受的转换)
【发布时间】: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);
}

【问题讨论】:

  • 问题显然是题外话。

标签: c++ binary


【解决方案1】:

线

if (ofile != NULL)

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

if (ofile)

【讨论】:

    【解决方案2】:

    而不是检查NULL

    你可以这样检查

    if(ofile.bad() != TRUE)
    {
       //Do Stuff
    }
    

    【讨论】:

      猜你喜欢
      • 2015-11-18
      • 1970-01-01
      • 2014-12-04
      • 1970-01-01
      • 2011-12-09
      • 2020-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多