【发布时间】:2010-01-02 08:50:59
【问题描述】:
错误信息:
这是什么意思?
我该如何解决?
错误 C2040:“==”:“int”与“const char [2]”的间接级别不同
代码:
#include <iostream>
#include <cmath>
using namespace std;
int round(double number);
//Assumes number >=0.
//Returns number rounded to the nearest integer.
int main()
{
double doubleValue;
char ans;
do
{
cout << "Enter a double value: ";
cin >> doubleValue;
cout << "Rounded that number is " <<round(doubleValue)<< endl;
cout << "Again? (y/n): ";
cin >> ans;
}
//Here is the line generating the problem, while(...);
while (ans == 'y' || ans == "Y");
cout << "End of testing.\n";
return 0;
}
//Uses cmath
int round(double number)
{
return static_cast<int>(floor(number + 0.5));
}
【问题讨论】:
-
我在您指出该行后就看到了问题,但这是一个非常无用的编译器错误消息。不难看出为什么人们对 C 及其类似语言感到沮丧。
标签: c++