使用 Visual Basic 更改C++中的"Press any key to Continue..."
Changing the "Press any key to Continue..." in C++ using Visual Basics
对于我们到目前为止在课堂上编写的每个程序,它都以默认的"按任意键继续..."结尾。如何更改此设置?我试过使用
cout<<"按任意键结束程序";系统("暂停>"nul)
但它仍然显示"按任意键继续"我输入的键。有什么想法吗?
这是我到目前为止所拥有的(随时指出我如何在其他领域进行改进! `
#include <iostream>
using namespace std;
#include <string>
using namespace std;
int main()
{
//Declaring my varibles
double persons = 0;
double tier1 = 125;
double tier2 = 100;
double tier3 = 75;
double cost = 0;
string hyphens = "";
system("cls");
cout << "-------------------------------------------------- " << endl;
cout << "Computer Programming Seminar" << endl;
cout << "-------------------------------------------------- " << endl<<endl;
cout << "Please enter the number of registrants: ";
cin >> persons;
cout << hyphens << endl;
if (0 < persons && persons < 6)
cost = persons * tier1;
else if (5 < persons && persons < 21)
cost = persons *tier2;
else if (persons >= 21)
cost = persons*tier3;
else
{
cost = 0;
cout << "Invalid Entry" <<endl << endl;
}
cout << "Total Amount Owed for the Seminar: $" << cost << endl;
cout << "-------------------------------------------------- " << endl;
cout << endl << endl << "Press any key to end the Seminar Program";
system("pause>nul");
return 0;
我的模式是:
std::cout << "Paused. Press Enter to continue.";
std::cin.ignore(100000, 'n');
您可以将提示更改为所需的任何内容。
按任意键继续... 这是默认值,永远不会更改。您可以尝试#include <conio.h>
而不是system("pause");
使用:
_getch();
您要避免的消息根本不来自您的程序。 它来自pause
命令。 因此,如果您想避免该消息,请不要再拨打system("pause")
。 在自己的代码中执行自己的 I/O。
我只是在使用 Console.WriteLine 显示自定义结束消息后将控制台前景色和背景色更改为黑色
让光标悬在半空中看起来有点草率,但它也超级容易,不会真正引起问题。
相关文章:
- 哪些类型可以转换为std::any
- 引用 std::any 或 not_yet_in_std::whatever 的惯用方式是什么?
- std::is_reference from std::any
- 是否可以从 std::any 创建 std::any 与 std::reference_wrapper?
- "reserved for any use"的含义是什么?
- boost::any 如何检查空值/未定义的值
- 使用 std::map 存储在 std::any 中,然后通过 std::any_cast 访问
- 可以有效地转换 std::any 与 std::any_cast
- 避免使用 std::any 编写相同的重复类型检查代码
- 广义 std::function (std::any 表示可调用对象)
- 如何在 c++17 中获取存储在 "any" 中的数据大小?
- 从 Any 包中提取和匹配 protobuf 消息类型名的首选方法
- 为电容式触摸传感器设置延迟以防止"double press"
- 如何获取"any"当前持有的类型的名称?
- 在可变参数模板函数中存储参数而不使用 boost::any
- 如何将参数包扩展为向量<any>
- 使用 Visual Basic 更改C++中的"Press any key to Continue..."
- 控制台应用程序不打印"Press any key to continue . . ."
- 如何实现"Press Any Key To Exit"
- Visual Studio 2010 "Press any key to continue . . ."不显示