在控制台中打印字符时出现问题



在我的代码中,我这样做了

int y=strcmp(s,s1);//before this I converted all the uppercase of the string input as lower case.
if(y==0)
{
cout<<"0"<<endl;
}
else if(y >= 1)
{
cout<<"1"<<endl;
}
else if(y<1)
{
cout<<"-1"<<endl;//problem was here
}

所以我把aaaaaaaA作为输入,0预期作为输出。但它给了我-1作为输出。 但是在我写这篇文章时的代码中:

int y=strcmp(s,s1);
if(y==0)
{
cout<<0<<endl;
}
else if(y >= 1)
{
cout<<1<<endl;
}
else if(y<1)
{
cout<<-1<<endl;
}

它给了我正确的答案。 我的问题是为什么会这样?

你删除了cout中的" "。你能显示你在第一轮得到的错误代码吗?

最新更新