C++比较字符串的字符

lvi*_*lvi -1 c++ string compiler-errors char

好的,所以输入是一个字符串.当我尝试编译以下代码时,我得到了

c.cpp:42:10: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
Run Code Online (Sandbox Code Playgroud)

为什么?

if(input[i] != ' ')
{   
    char s = input[i];
    if(s == "+")
    {
         ...
    }
}
Run Code Online (Sandbox Code Playgroud)

Vla*_*cow 5

在此语句中使用单引号

if(s == "+")
Run Code Online (Sandbox Code Playgroud)

就在这里

if(s == '+')
Run Code Online (Sandbox Code Playgroud)

  • 更好地解释_why_.这个答案解决了OP的编译器错误,但让他对代码更改意味着什么绝对无能为力.教学不是一个好方法. (5认同)