解除分配和重新分配内存.在 FLTK 中重置多边形


#include "Simple_window.h"   
#include "Graph.h"          
#include <math.h>
#include <iostream>
#include <limits>
using namespace std;
int main(){
    Simple_window win(Point(100,100),600,400,"Marks");

    Graph_lib::Polygon poly;
    bool over = true;
    int n = 0;
    while(over){
            Marks pp("x");
            pp.add(Point(300,200));
            cout<<"Enter number of sides (3 or more): ";
            while(!(cin>>n)){
                cin.clear();
                  cin.ignore(numeric_limits<streamsize>::max(), 'n');
                  cout<<"Enter number of sides (3 or more): ";
            }
            if(n<3){
                break;
            }
    //Finding the angle and number of sides...
        if(n%2 != 0){
        //logic for polygon...

          }
        }else{
        //logic for polygon...
            }

        }
    poly.set_color(Color::magenta);  // adjust properties of poly
    win.attach (poly);           // connect poly to the window
    win.attach(pp);
    win.wait_for_button();       // Display!

    }

}

这个程序做什么,它制作了 n 边多边形。在我设置了多边形之后。我想重置它。在我输入多边形中的边数之后。我单击"下一步",它会再次询问我有多少个多边形并重复该过程。有人叫我叫删除。但是我不确定我将如何输入它。就像删除多边形点一样?还是删除多边形?我尝试了一些,但我不断收到错误。

我的第二个问题是在第38行。最初我有它,所以如果我输入的数字小于 3,程序将结束。但该计划不会结束。所以我不得不使用休息时间;

if(n<3){
    over=false;
    cout<<"why wont this end ?"<<endl;
}

布尔值设置为 True。而真正的循环。如果 n <3 以上为假。因此结束程序?它不会结束。

如果将声明粘贴在第一个 while 循环中,则无需重置多边形。

while(over){
    Graph_lib::Polygon poly;
    ...
    win.wait_for_button();
}

回复:为什么你的程序不会结束。 休息就足够好了,但如果你不喜欢使用休息

  • 使用继续
  • 将循环体的其余部分放在 else 子句中

编辑:回复:更改标题:我不知道Simpe_Window界面:它不是FLTK的一部分 - 它是Stroustrup的创作。 如果它派生自FL_Window,请使用标签(新标题(。

最新更新