| 4 | 1/1 | 返回列表 |
| 查看: 1524 | 回復: 3 | ||
[求助]
C++中exit(1)什么意思
|
| C++程序中,exit(1)什么意思,有什么作用? |

銀蟲 (小有名氣)

至尊木蟲 (著名寫手)
驃騎將軍
|
就是強制退出程序,并告訴系統(tǒng),運行出錯(返回非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++進程開始時是由系統(tǒng)的一個啟動函數(shù)調用了主函數(shù)main函數(shù)的: int nMainRetVal = main(); 當從main函數(shù)退出后,啟動函數(shù)便調用exit函數(shù),并且把nMainRetVa傳遞給它. 所以,任何時候都會調用exit函數(shù)的,正常情況下,main函數(shù)不會調用exit函數(shù)的,而是由return 0; 返回值給nMainRetVal的,exit再接收這個值作為參數(shù)的.所以,正常情況下是以exit(0)退出的. 如果,你程序發(fā)生異常,你可以在main函數(shù)中調用exit(1),強制退出程序,強制終止進程.其中1表示不正常退出。 #include #include void main() { int ch; cout<< "Yes or no? " < if( ch == 'Y' ) exit( 1 ); else exit( 0 ); } |

| 4 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 一志愿中南大學化學學碩0703總分337求調劑 +4 | niko- 2026-03-22 | 4/200 |
|
|---|---|---|---|---|
|
[考研] 317求調劑 +12 | 申子申申 2026-03-19 | 18/900 |
|
|
[考研] 298求調劑 +6 | 上岸6666@ 2026-03-20 | 6/300 |
|
|
[考研] 310求調劑 +4 | baibai1314 2026-03-16 | 4/200 |
|
|
[考研] 一志愿上海交大生物與醫(yī)藥專碩324分,求調劑 +3 | jiajunX 2026-03-22 | 3/150 |
|
|
[考研] 求調劑 +6 | 十三加油 2026-03-21 | 6/300 |
|
|
[考研] 生物學071000 329分求調劑 +5 | 我愛生物生物愛?/a> 2026-03-17 | 5/250 |
|
|
[考研] 初試 317 +7 | 半拉月丙 2026-03-20 | 7/350 |
|
|
[考研] 297求調劑 +3 | 喜歡還是不甘心 2026-03-20 | 3/150 |
|
|
[考研] 279求調劑 +5 | 紅衣隱官 2026-03-21 | 5/250 |
|
|
[考研] 材料與化工(0856)304求 B區(qū) 調劑 +3 | 邱gl 2026-03-21 | 3/150 |
|
|
[考研] 301求調劑 +10 | yy要上岸呀 2026-03-17 | 10/500 |
|
|
[考研] 二本跨考鄭大材料306英一數(shù)二 +3 | z1z2z3879 2026-03-17 | 3/150 |
|
|
[考研] 274求調劑 +10 | S.H1 2026-03-18 | 10/500 |
|
|
[考研] 材料專碩英一數(shù)二306 +7 | z1z2z3879 2026-03-18 | 7/350 |
|
|
[考研]
|
不想起名字112 2026-03-19 | 3/150 |
|
|
[考研] 生物學調劑招人。! +3 | 山海天嵐 2026-03-17 | 4/200 |
|
|
[考研] 085601材料工程專碩求調劑 +10 | 慕寒mio 2026-03-16 | 10/500 |
|
|
[考研] 0703化學調劑 +3 | 妮妮ninicgb 2026-03-17 | 3/150 |
|
|
[考研] 考研調劑 +3 | 淇ya_~ 2026-03-17 | 5/250 |
|