gpt4 book ai didi

c++ - 错误 1 ​​错误 C2678 : binary '!=' : no operator found which takes a left-hand operand of type 'std::ofstream' (or there is no acceptable conversion)

转载 作者:太空宇宙 更新时间:2023-11-04 15:39:55 25 4
gpt4 key购买 nike

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

Error 1 error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::ofstream' (or there is no acceptable conversion) c:\users\yuser\desktop\injector\injector\WriteLog.h 27 1 Injector

谁能帮我解决这个问题

代码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);
}

最佳答案

线

if (ofile != NULL)

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

if (ofile)

关于c++ - 错误 1 ​​错误 C2678 : binary '!=' : no operator found which takes a left-hand operand of type 'std::ofstream' (or there is no acceptable conversion),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25191128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com