代码陷入空格循环,求解

##C++代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    char d;
    cin>>a>>b>>d>>c;
    for (int f=0;f++;f<b)
        {
            cout<<d;
    }
    cout<<endl;
    if (c==0)
        {
            for (int e=2;e++;e<a)
                {
                    cout<<d;
                    for (int g=2;g++;g<b)
                        {
                            cout<<" ";
                    }
                    cout<<d<<endl;
            }
    }
    else
        {
            for (int e=2;e++;e<a)
                {
                    for (int g=0;g++;g<b)
                        {
                            cout<<d;
                    }
                    cout<<endl;
            }
    }
    for (int f=0;f++;f<b)
        {
            cout<<d;
    }
    return 0;
}
  • 输入7 7 @ 0后只显示一个@然后空格死循环

更改后已解决

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    char d;
    cin>>a>>b>>d>>c;
    for (int f=0;f<b;f++)
        {
            cout<<d;
    }
    cout<<endl;
    if (c==0)
        {
            for (int e=2;e<a;e++)
                {
                    cout<<d;
                    for (int g=2;g<b;g++)
                        {
                            cout<<" ";
                    }
                    cout<<d<<endl;
            }
    }
    else
        {
            for (int e=2;e<a;e++)
                {
                    for (int g=0;g<b;g++)
                        {
                            cout<<d;
                    }
                    cout<<endl;
            }
    }
    for (int f=0;f<b;f++)
        {
            cout<<d;
    }
    return 0;
}

查看全部
junsi_qzqz0033
junsi_qzqz0033
2019/08/28 13:12
  • c++
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复