迭代char *错误没有从char *转换为int

时间:2017-04-07 14:18:07

标签: c++ pointers char

我按照以下方式迭代char *,但在指示的行上,我收到错误C2446'!='没有从char *到int的转换。

        int errorLineNumber = 0;
        char* json;  //this is a long json with multiple \n's in it.
        int offset = errorOffset;
        char* p = json + offset;
        while (*p-- != '\n' && offset--); //check that this gives offset on that error line and not char position of end of last line before error
        errorLineOffset = errorOffset - offset; //get offset on error line only

        //count lines to json error
        long errorLineNumber = 0;
        while (*p!= json) //this is error line
            errorLineNumber += *p-- == '\n';

我看了conversion const char to tchar,但它有点不同,我也看了conversion const char to int,我仍然不认为是同一个问题,除非我&#39我错过了什么。

如果有人知道我错过了什么,那就太棒了。谢谢!

1 个答案:

答案 0 :(得分:1)

排队

while (*p != json) 

你将*p类型charjson进行比较,根据上面的代码应该是指针,我假设它是`const char *类型。所以你应该做

while (p != json) ... 
相关问题