字符串比较很奇怪

时间:2013-01-18 21:45:45

标签: c++

我一直在这里绞尽脑汁:

cout << orig << " * " << count << endl;
string check = multiply2(orig, count);
cout << "Check was: " << check << " and number is: " << number << endl;
cout << "the compare result: " << check.compare(number) <<  endl;
if(check.compare(number) == 0)
{
  cout << "wahoo it matches!!! we did it! " << endl;
}
else
{
  cout << "Doesnt Match " << endl;
}

我希望它匹配并打印wahoo it matches!!! we did it!,但它反而说它不匹配。

这是我的输出:

1 * 900000
Check was: 900000 and number is: 90000
the compare result: 1
Doesnt Match

任何人都知道他们为什么不匹配?

1 个答案:

答案 0 :(得分:6)

您将900000(如9E5中)与90000进行比较(如9E4中所示)。电脑是对的。