求助,编译错误

P1307 [NOIP2011 普及组] 数字反转

青岛地铁 @ 2017-04-02 20:55:25

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    char a[100];
    int n,i;
    cin>>a;
    n=strlen(a);
    if(a[0]=='-')
    cout<<"-";
    while(a[n-1]!="0")
    {
        n--;
    }
    for(i=n-1;i>=0;i--)
    {
        if(a[i]!="-")
        cout<<a[i]
    }
}
12    16    D:\c++语言测试\未命名1.cpp    [Error] ISO C++ forbids comparison between pointer and integer [-fpermissive]
18    12    D:\c++语言测试\未命名1.cpp    [Error] ISO C++ forbids comparison between pointer and integer [-fpermissive]
这是咋回事?(我目前没有提交)

by 青岛地铁 @ 2017-04-02 20:58:05

等一下,那个cout<<a[i]后面没有分号(不过好像不是这个事,我加了分号也不行)


by x_faraway_x @ 2017-04-02 21:34:35

while(a[n-1]!="0")

改为 while(a[n-1]!='0')


by x_faraway_x @ 2017-04-02 21:35:19

f(a[i]!="-")也是把双引号改成单引号


|