2015-08-09 62 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