C++日历,在我看到输出之前关闭
C++ calender, closes before I can see output
所以基本上我创建了这个日历,当它输出时,您可以简要地看到它是正确的,但它只是关闭,有人可以帮我保持打开状态以显示输出吗?我知道我应该知道这是什么,但这花了我很长时间才做,我的思想只是不在正确的地方。谢谢
#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <iomanip>
#include "float.h"
#include <stack>
using namespace std;
using std::stack;
int calendar[6][7];
void cal(int y, int z) // y is number of days and z is the number corresponding
{ // to the first day
int n = 1;
for (int j = z - 1; j<7; j++)
{
calendar[0][j] = n;
n++;
}
for (int i = 1; i<6 && n <= y; i++)
{
for (int k = 0; k<7 && n <= y; k++)
{
calendar[i][k] = n;
n++;
}
}
}
int main()
{
int d;
int day;
cout << "Enter number of days : ";
cin >> d;
cout << "Enter first day of the month(1 for monday 7 for sunday..) : ";
cin >> day; cout << "n";
cal(d, day);
cout << "M T W T F S S" << endl;
cout << "n";
for (int i = 0; i<6; i++)
{
for (int j = 0; j<7; j++)
{
cout << calendar[i][j] << "t";
}
cout << "" << endl;
}
}
使用 std::cin.get()
使窗口保持打开状态。
由于没有人提到它 - 您也可以在Windows系统系列上做system("pause")
。它以最"优雅"的方式满足您的需求。
最简单的方法可能是在 main 结束之前请求一些输入:
std::cin.ignore(std::numeric_limits<std::streamsize>::max());
std::cin.ignore();
这将等待 Enter 键被点击:由于只完成了一些数字输入,因此输入缓冲区中至少还有一个换行符。第一行删除任何已输入的行。然后,第二行等待回车键。
我通常只用getchar()
来等待用户输入,比std::cin.get()
短。
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- C++格式化输出问题
- 将值从二维数组输出到文本文件
- 集合上的输出迭代器:assign和increment迭代器
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- 如何将具有功能的日历程序输出到.txt文件
- C++日历,在我看到输出之前关闭
- c++;使用多种功能创建年度日历并打印到输出文件