錯誤消息:C++錯誤C2040?
這是什麼意思?
我該如何解決?
錯誤C2040: '==': '詮釋' 的不同之處,從 '爲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及其同類感到沮喪。 – 2010-01-02 08:58:27