C ++按键:getch,cin.get? [英] C++ keypress: getch, cin.get?

查看:75
本文介绍了C ++按键:getch,cin.get?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个循环运行的Win32程序.我希望能够在等待按键时暂停该程序.不管我使用任何键"还是特定键都没有关系,但是我需要冻结程序,直到按下某项为止.

I have a Win32 program that runs on a loop. I would like to be able to pause that program while awaiting a keypress. It doesn't matter whether I use 'any key' or a specific key, but I need to have the program freeze until I press something.

我想知道应该使用哪个命令.我正在使用Visual C ++,并且编译器无法识别以下任何命令:

I am wondering which command I should use. I am working with Visual C++ and the compiler doesn't recognise any of the following commands:

cin.get()

std::cin.get()

getch()

我对C ++比较陌生.我知道在控制台应用程序中,这是一个非常简单的操作(cin.get),但在Win32中可能会更加困难.任何简单的解决方案或解决方法,将不胜感激.该程序是定制的,可以在单个科学实验中使用,因此,现在,如果解决方案有点笨拙,我就不会大惊小怪(!)

I am relatively new to C++. I understand that in a console app this is a fairly simple action to take (cin.get), but that it can be more difficult in Win32. Any simple solution or workaround would be appreciated. The program is bespoke to be used in a single scientific experiment, so for now I'm not fussed if the solution is a little botchy(!)

很抱歉,如果我错过了我的问题中的任何重要信息.

Apologies if I've missed any important info from my question.

推荐答案

您都不应该使用.

您应该使用

#include <iostream>
...
int main()
{
   ... 
   std::cin.ignore(); //why read something if you need to ignore it? :)
}'

此处是文档

这篇关于C ++按键:getch,cin.get?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆