我運行的是DUP1例如從圍棋編程語言的書(如下圖所示相關的代碼):for input.Scan() { counts[input.Text()]++}輸入幾行文本后,我想終止該Scan()方法。我嘗試過 Ctrl+D、Ctrl+Z 和許多其他組合鍵,但都沒有成功。只有 Ctrl+C 有效,但這也會終止程序。如何在Scan()不退出程序的情況下終止from 終端?我正在使用 os.Stdin 在 Windows 7 上進行開發。[編輯]Ctrl+Z 不起作用:謝謝。但這對我不起作用:C:\prj\src\gopl\>go run dup1.goI have tried all these combinations from the terminal^Z^X^V^B^N^A^D^F^G^K^L^Q^W^E^R^T^Y^U^O^P2(Notes: only Ctrl + C works here)C:\prj\src\gopl\>如果我在 Ubuntu 中運行此程序,則只能Ctrl + D工作,Ctrl + Z將停止該程序Ctrl + C并將終止它。
3 回答

蕭十郎
TA貢獻1815條經驗 獲得超13個贊
ctrl + shift + d 如果它是新行中的第一個字符,則會將 EOF 發送到終端。
go run main.go
> line one
> another line
> another line
> ctrl + shift + d
你應該看到輸出
2 another line
如本評論https://stackoverflow.com/a/21658005/1522019 中所述。
您可以使用stty all來查找 EOF 組合。我一直在做ctrl + d這件事在我看來是一樣的ctrl + D。
- 3 回答
- 0 關注
- 355 瀏覽
添加回答
舉報
0/150
提交
取消