[問題] thread跟stdin stdout & termios.h

看板C_and_CPP (C/C++)作者 (owo)時間10年前 (2015/06/24 12:01), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Linux 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) termios.h thread unistd.h 問題(Question): 我宣告了兩個thread物件 第一個不斷的輸出printf("1"); 第二個則是用自定義的getch()去監看輸入狀況 如果輸入a則停止程式、其餘的則輸出按下的值然後程式繼續 但是執行出來程式的output會卡在getch前 直到getch讀取到值以後才會把之前的output全部print出來 想問要如何做才能讓他不要等input...... 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) http://paste.plurk.com/show/2192424/ 補充說明(Supplement): 剛接觸thread如有觀念不對的地方 還請各位指教! 感謝大家m(_ _)m -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.123.74 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1435118477.A.AEE.html

06/24 13:24, , 1F
std::cout << std::flush;
06/24 13:24, 1F

06/24 15:05, , 2F
成功了O_O!!
06/24 15:05, 2F

06/24 15:05, , 3F
感謝!!!
06/24 15:05, 3F
文章代碼(AID): #1LYYkDhk (C_and_CPP)
文章代碼(AID): #1LYYkDhk (C_and_CPP)