2015-08-09 55 views
-1

我想让程序读取文本文件并使用该行功能,但我得到一个错误!C++错误来读取字节线

5 IntelliSense: operand types are incompatible ("BYTE" and "char *") 
Error 1 error C2446: '==' : no conversion from 'char *' to 'int' 
Error 2 error C2040: '==' : 'int' differs in levels of indirection from 'char [260]' 

我的代码:

char* ReadINI(char* szSection, char* szKey, const char* szDefaultValue) 
{ 
    char* szResult = new char[255]; 
    memset(szResult, 0x00, 255); 
    GetPrivateProfileString(szSection, szKey, szDefaultValue, szResult, 255, ".\\Config.ini"); 
    return szResult; 
} 

int main (Classdata* Cdata) 
{ 
    BYTE ByteID = Cdata->ByteType; 
    static char ReadByte[MAX_PATH]; 
    sprintf(ReadByte, "%s", ReadINI("CONFIG", "Key", "0")); 

    if (ByteID == ReadByte) 
    { 
     printf("Byte Value: %p", ReadByte); 
    } 
} 
+0

'使用函数行',您的标题是无意义的。 – EJP

回答

0

首先,你是比较ByteId(一unsigned char`)与ReadByte(一个char *),它不太可能是有意义的。

在不相关的说明中,szResult使用new创建,但从未使用delete d。

0

不可能更清楚ByteId是​​,ReadBytechar[260]。你不能比较整数和数组。也许(只是猜测)你的意思是ByteId == ReadByte[0]

另外,你有内存泄漏的ReadIni,并ReadByte声明为static没有很好的理由,我可以看到,和你的main声明是不合法的。

-1

我用另一种类型的函数来读取文件!对不起的解释是我正在做一个私人项目!感谢大家的帮助

功用:

UINT value = GetPrivateProfileInt("Section", "Key", DEFAULT_VALUE, "program.ini"); 

THX的一切!

+0

您至少可以解决您的问题,使其易于理解。或删除它。 – EJP