【发布时间】:2014-03-28 10:15:10
【问题描述】:
我有一个程序,当输入命令 (cin) 帮助时,它会显示帮助说明。该注释看起来有点像这样:
C++
if (cmd == "help")
{
cout << "▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄\n";
cout << "██ Help Menu ██\n";
cout << "▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀\n";
cout << "Press a key then enter to continue\n" << string( 10, '\n' );
cin.ignore();
return 0;
}
字符串 var cmd 是 'help'。
我在 Mac 上编译它并包含:
C++
#include <iostream>
#include <string>
using namespace std;
我可以使用什么代码来完成这项工作? cin.ignore(); 不接缝做任何事情,而下界做 cin.get();
【问题讨论】:
-
你问的是如何获取用户输入?
-
不,是的,我需要程序停止,直到在键盘上按下回车
-
你的意思是停止还是等待? Stop 建议一些后台任务,例如视频,wait 建议等待按键。
-
在这 10 个换行符上,请注意每个人都有不同大小的终端。对于这种类型的屏幕布局,我推荐使用 curses 库。