| 5 | 1/1 | 返回列表 |
| 查看: 1529 | 回復(fù): 3 | |||
| 當(dāng)前只顯示滿足指定條件的回帖,點(diǎn)擊這里查看本話題的所有回帖 | |||
[求助]
C++中exit(1)什么意思
|
|||
| C++程序中,exit(1)什么意思,有什么作用? |

至尊木蟲 (著名寫手)
驃騎將軍
|
就是強(qiáng)制退出程序,并告訴系統(tǒng),運(yùn)行出錯(返回非0值給系統(tǒng)) void exit (int status); Terminates the process normally, performing the regular cleanup for terminating programs. If status is zero or EXIT_SUCCESS, a successful termination status is returned to the host environment. If status is EXIT_FAILURE, an unsuccessful termination status is returned to the host environment. Otherwise, the status returned depends on the system and library implementation. |

銀蟲 (小有名氣)

|
C++進(jìn)程開始時是由系統(tǒng)的一個啟動函數(shù)調(diào)用了主函數(shù)main函數(shù)的: int nMainRetVal = main(); 當(dāng)從main函數(shù)退出后,啟動函數(shù)便調(diào)用exit函數(shù),并且把nMainRetVa傳遞給它. 所以,任何時候都會調(diào)用exit函數(shù)的,正常情況下,main函數(shù)不會調(diào)用exit函數(shù)的,而是由return 0; 返回值給nMainRetVal的,exit再接收這個值作為參數(shù)的.所以,正常情況下是以exit(0)退出的. 如果,你程序發(fā)生異常,你可以在main函數(shù)中調(diào)用exit(1),強(qiáng)制退出程序,強(qiáng)制終止進(jìn)程.其中1表示不正常退出。 #include #include void main() { int ch; cout<< "Yes or no? " < if( ch == 'Y' ) exit( 1 ); else exit( 0 ); } |

| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 298求調(diào)劑 +3 | 種圣賜 2026-03-28 | 3/150 |
|
|---|---|---|---|---|
|
[考研] 材料學(xué)碩333求調(diào)劑 +10 | 北道巷 2026-03-24 | 10/500 |
|
|
[考研] 343求調(diào)劑 +5 | 愛羈絆 2026-03-28 | 5/250 |
|
|
[考研] 295材料工程專碩求調(diào)劑 +7 | 1428151015 2026-03-27 | 7/350 |
|
|
[考研] 322求調(diào)劑 +5 | 舊吢 2026-03-24 | 5/250 |
|
|
[考研] 277跪求調(diào)劑 +5 | 1915668 2026-03-27 | 9/450 |
|
|
[考研] 材料求調(diào)劑 一志愿哈工大總分298分,前三科223分 +5 | dongfang59 2026-03-27 | 5/250 |
|
|
[考研] 331環(huán)境科學(xué)與工程求調(diào)劑 +3 | 熠然好運(yùn)氣 2026-03-27 | 3/150 |
|
|
[考研]
|
18419759900 2026-03-25 | 8/400 |
|
|
[考研] 287求調(diào)劑 +10 | land xuxu 2026-03-26 | 10/500 |
|
|
[考研] 考研化學(xué)308分求調(diào)劑 +10 | 你好明天你好 2026-03-23 | 12/600 |
|
|
[考研] 材料求調(diào)劑 +5 | .m.. 2026-03-25 | 5/250 |
|
|
[考研] 一志愿吉大071010,316分求調(diào)劑 +3 | xgbiknn 2026-03-27 | 3/150 |
|
|
[考研] 329求調(diào)劑 +5 | 1() 2026-03-22 | 5/250 |
|
|
[考研] 一志愿南航 335分 | 0856材料化工 | GPA 4.07 | 有科研經(jīng)歷 +6 | cccchenso 2026-03-23 | 6/300 |
|
|
[考研]
|
13659058978 2026-03-24 | 4/200 |
|
|
[考研] 335求調(diào)劑 +4 | yuyu宇 2026-03-23 | 5/250 |
|
|
[考研] 284求調(diào)劑 +3 | yanzhixue111 2026-03-23 | 6/300 |
|
|
[考研] 384求調(diào)劑 +3 | 子系博 2026-03-22 | 6/300 |
|
|
[考研] 269求調(diào)劑 +4 | 我想讀研11 2026-03-23 | 4/200 |
|