[問題] 新手 - 想要讓程式暫停

看板C_and_CPP (C/C++)作者 (shark)時間16年前 (2009/02/24 23:21), 編輯推噓4(405)
留言9則, 8人參與, 最新討論串1/1
一個簡單的小程式 #include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; int main () { int ft, inches; cout << "Please Enter the feet" <<endl; cin >> ft; inches = 12*ft; cout << ft << " feet is equal to " << inches << " inches." <<endl; getchar(); return 0; } 應該是用getchar() 讓程式停下來 可是在我key完ft的值之後 不知道他就一路跑下去了,沒停下來 然後我就加了一堆標頭檔試試看 用了Dev-C++跟linux的g++ compile 結果都一樣 請大大解惑 謝謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.133.158.92

02/24 23:23, , 1F
cin.ignore(); cin.get();
02/24 23:23, 1F

02/24 23:23, , 2F
<conio.h>標頭檔勒? 我記得要用這個
02/24 23:23, 2F

02/24 23:24, , 3F
可能getchar抓到你的enter鍵, 就過去了
02/24 23:24, 3F

02/24 23:26, , 4F
打兩個getchar()試試
02/24 23:26, 4F

02/24 23:26, , 5F
回二樓,不是包含在<stdio.h>裡了嗎,我剛才趴文看到的
02/24 23:26, 5F

02/24 23:27, , 6F
四樓的管用,謝謝,原因可能是三樓講的(我想)
02/24 23:27, 6F

02/24 23:53, , 7F
改用 conio.h 的 getch() 試試。
02/24 23:53, 7F

02/25 13:44, , 8F
這應該也是萬年op的問題了....
02/25 13:44, 8F

05/07 15:26, , 9F
建議不要用system("pause");不好用!
05/07 15:26, 9F
文章代碼(AID): #19f11fMf (C_and_CPP)
文章代碼(AID): #19f11fMf (C_and_CPP)