0

所以基本上我创建了这个日历,当它输出时,你可以简单地看到它是正确的,但它只是关闭了,有人可以帮我保持打开状态以显示输出吗?我知道我应该知道这是什么,但这花了我很长时间才完成,而且我的想法不在正确的地方。谢谢


#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; 
    }
}
4

4 回答 4

1

用于std::cin.get()保持窗口打开。

于 2013-11-09T23:13:02.237 回答
0

由于没有人提到它 - 你也可以system("pause")在 Windows 系统系列上做。它以最“优雅”的方式满足您的需求。

于 2013-11-09T23:56:22.207 回答
0

最简单的方法可能是在 main 结束之前要求一些输入:

std::cin.ignore(std::numeric_limits<std::streamsize>::max());
std::cin.ignore();

这将等待回车键被击中:由于只是完成了一些数字输入,因此输入缓冲区中至少还有一个换行符。第一行去掉任何已经输入的行。然后第二行等待输入键。

于 2013-11-09T23:12:56.143 回答
0

我通常只是getchar()用来等待用户输入,它比std::cin.get().

于 2013-11-09T23:16:20.147 回答