Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++中日历的间距问题_C++_Calendar - Fatal编程技术网

C++中日历的间距问题

C++中日历的间距问题,c++,calendar,C++,Calendar,我想显示日历使用单循环,但主要的问题是间距,我不能给他们之间的适当数量的空间 cout << "M T W TH FRI Sa Su " << endl; for (int i = 1; i <= 31; i++) { if (i % 7 == 0) { cout << i << endl << " "; } else { cout

我想显示日历使用单循环,但主要的问题是间距,我不能给他们之间的适当数量的空间

cout << "M   T   W   TH   FRI   Sa   Su " << endl;

for (int i = 1; i <= 31; i++)
{
    if (i % 7 == 0)
    {
        cout << i << endl << "  ";
    }
    else
    {
        cout << i << "   ";
    }
}

cout << endl;
我的输出


现在搜索真的那么难吗?请参见示例。我想显示日期,但在i>9之后存在间距问题
#include<iostream>
using namespace std;
int main()
{
cout<<endl<<" S  M  T  W  T  F  S"<<endl<<endl;
int k=1;
for(int i=0;i<6;i++)
{
for(int j=0;j<7;j++)
{
    if(k>31){break;}
    if(k<10){cout<<" "<<k++<<" ";}
    else{cout<<k++<<" ";}
}cout<<endl;
}
return 0;
}