2013-01-18 43 views
0

我一直都在這裏折磨我的大腦:字符串比較是怪異

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 

任何人有任何想法,爲什麼他們arent匹配?

+0

它們各自的類型是什麼?你是如何設置它們的? – 0x499602D2

+6

嗯,一個數字有5個數字,另一個有6個數字.... –

回答

6

您比較900000(如9E5)與90000(如9E4)。電腦是對的。

+0

電腦在這個東西很不錯。我希望我是一臺電腦。 –

+0

編碼24小時後,很容易錯過簡單的事情;) – Deekor