使用bool類型定義變量時(shí),編譯出錯(cuò)。錯(cuò)誤信息顯示如下:
'bool' undeclared (first use in this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
C語言(或C++)里本身沒有bool這種布爾類型。有些編譯器可以識(shí)別,那也是因?yàn)榫幾g器自己定義了bool類型,比如:#define bool int。
C語言里,一般用整型變量來實(shí)現(xiàn)布爾型變量的功能。當(dāng)用條件語句,如if,進(jìn)行判斷時(shí),值為0時(shí)返回false,其它都返回true。