C++中如何实现Press any Key to continue功能

54lem 2003-10-29 06:36:38
不用 conio.h 里面的 getch() getche()

如何实现按任意键 执行下一步操作的功能
...全文
576 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
AkiraChing 2003-12-16
  • 打赏
  • 举报
回复
cout<<"Press any Key to continue";
cin.ignore();
AkiraChing 2003-10-29
  • 打赏
  • 举报
回复
cout<<"Press any Key to continue";
getchar();
beyondtkl 2003-10-29
  • 打赏
  • 举报
回复
确实.
54lem 2003-10-29
  • 打赏
  • 举报
回复
是控制台程序
我想用标准 C++ 库来实现

标准 C++ 库没有 conio.h (属于 C 函数库)头文件
可能确实没有办法了
redleaf0000 2003-10-29
  • 打赏
  • 举报
回复
如果是控制台程序可以用_getch函数等待用户按键
要是图形界面程序的话似乎只能用模式对话框了
54lem 2003-10-29
  • 打赏
  • 举报
回复
用上了API了呀
就用标准 C++ 运行库难道不能解决?
carbon107 2003-10-29
  • 打赏
  • 举报
回复
if (pMsg.message== WM_KEYDOWN)
carbon107 2003-10-29
  • 打赏
  • 举报
回复
PreTranslateMessage(MSG* pMsg)
{
if (pMsg.== WM_KEYDOWN)
AfxMessageBox("haha");
}
捕获消息
54lem 2003-10-29
  • 打赏
  • 举报
回复
有没有 C++ 标准库里面的函数可以解决这个问题?

如果没有,应该怎样做才能实现同样的功能呀
yaoha2003 2003-10-29
  • 打赏
  • 举报
回复
是个难题,UP
guessing and betting number game The user starts with 100 dollars, and is able to bet and guess until they quit or have no more money. In each turn, they are asked for a bet. If they enter 0, then the program should give a farewell message and quit. The bet must be positive and within their available balance, If they enter incorrectly, the program should set the bet to their balance and tell them this. Once a bet is entered, they must pick a number between 1 and 10 (you do not need to errorcheck or correct this). This guess is then compared to a number the computer randomly generates each time (also between 1 and 10). If the guess is correct, the user wins the amount of their bet. If the guess is incorrect, the user will lose their bet divided by 5 and multiplied by the distance from the correct number - e.g. if the bet is 50, the computer’s number is 5 and the user guesses 7, then the user will lose 20 dollars( 50/5 * (7-5) = 20 ). However, they should not lose more than their balance, so if their balance is 50, the bet is 40, the computer’s number is 1 and the user guesses 10, (40/5 * (10-1) = 72 > 50 )then they should lose 50. After each turn, the program should display that turn's winnings (or loss amount) and the new balance,and then repeat the game until the user either quits or has no money left. Dollar values should be formatted in the standard way with two decimal places and a $ in front. Sample output from the program is below. You should make your program match this exactly (except for your name). An appropriate welcome message with your name in it should be shown at the start of the program. Assignment 1 : Guessing Game Written by yourname Please enter your bet (up to $100.00): $50 Guess a number between 1 and 10: 5 Correct! You win $50.00 Your new balance is $150.00 Please enter your bet (up to $150.00): $200 Your bet is $150.00 Guess a number between 1 and 10: 6 Wrong! The computer chose: 4 You lose $60.00 Your new balance is $90.00 Please enter your bet (up to $90.00): $80 Guess a number between 1 and 10: 1 Wrong! The computer chose: 7 You lose $90.00 Thank you for playing! Press any key to continue . . . Another Sample: CP1200 Guessing Game Written by Lindsay Ward Please enter your bet (up to $100.00): $-20 Your bet is $100.00 Guess a number between 1 and 10: 5 Wrong! The computer chose: 2 You lose $60.00 Your new balance is $40.00 Please enter your bet (up to $40.00): $10.50 Guess a number between 1 and 10: 12 Wrong! The computer chose: 2 You lose $21.00 Your new balance is $19.00 Please enter your bet (up to $19.00): $0 Thank you for playing! Press any key to continue . . . srand( static_cast(time(0))) ; 初始化 computerNumber = 1 + rand( ) % 10 ; 产生随机数 cout << fixed << setprecision(2) ; 控制输出显示2位小数

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧