使用任意键(c ++)停止程序
Stopping the program with any key(c++)
如何制作一个在按下某个键时停止程序的函数?(该函数需要作为线程运行(。我试过了,但不起作用
_getch() == true;
if(_getch() == true){
exit(0);
}
你可以使用 ncurses 库,
#include <ncurses.h>
...
initscr(); /* Start curses mode */
getch(); /* Wait for user input */
endwin(); /* End curses mode */
...
您可以在NCURSES编程HOWTO中找到与之相关的文档
答案存在于askubuntu。
以下内容适用于Windows和linux/unix:
#include <iostream>
...
std::cout << "Press 'Return' to end." << std::endl;
cin.sync(); // instead of flush()
std::cin.get();
第一个
std::cin.sync()
清除输入 que,下一个命令 等待输入。
相关文章:
- 如何在 WindowProc 处理程序中区分箭头键和数字键盘?
- 如何将我的程序添加到文件和文件夹的macOS右键单击菜单?
- 有没有办法使用 mongocxx 驱动程序从 GridFS 集合的文件下载任意范围?
- 如何优化C++键值程序以获得更快的运行时间
- 如何使用键盘的特殊键,如Command、Shift、Alt、Tab或C/C++程序中的功能键
- 如何隐藏在c++中运行powershell脚本时按任意键继续
- Qt 键按事件处理程序仅在按下 ctrl、alt 或 shift 键时做出反应
- 当我尝试构建此程序时,出现此错误:需要左键作为赋值的左操作数
- 如何在我的 Windows 应用程序中捕获按下和释放的 CTRL 键?
- 如何在给定任意数量的整数的情况下创建一个唯一键?并使用该键存储,然后从地图中查找
- 使用任意键(c ++)停止程序
- Cassandra驱动程序用多个键查询
- 如何在C 中按ENTER/返回键时退出程序循环
- C++代码在 Gedit 中有效,但在 VS 中不起作用(它只是打印"按任意键退出......"。消息)
- 通过按任意键退出"do while"而不按回车键?
- Microsoft Visual Studio 2013 C++--按任意键可在新行上继续
- 在Linux c++中按任意键继续
- 如何在按任意键时使无限循环停止?
- 按任意键继续播放.在Visual Studio Express c++中
- 如何让玩家按任意键继续