C++11 图形错误,为什么程序会崩溃?
我试图为类测试的每个对象创建一个条。有一个私有变量,status。如果C++11 图形错误,为什么程序会崩溃?,c++11,C++11,我试图为类测试的每个对象创建一个条。有一个私有变量,status。如果status==0的值,则该条颜色将变为红色,否则将变为绿色。来自for循环的多个输入后,程序的图形窗口崩溃。请帮助我,我哪里做错了 /* bar example */ #include <iostream> #include <graphics.h> using namespace std; #include <stdlib.h> #include <stdio.h>
status==0
的值,则该条颜色将变为红色,否则将变为绿色。来自for循环的多个输入后,程序的图形窗口崩溃。请帮助我,我哪里做错了
/* bar example */
#include <iostream>
#include <graphics.h>
using namespace std;
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
class test
{
private:
int x;
public:
test()
{
}
int getX()
{
if(x==0)
{
cout << "Room Empty";
}
else
if (x==1)
{
cout << "Room Occupied";
}
return x;
}
void setX(int check)
{
x=check;
this->update();
}
void update()
{
//Block to change the colour of the bar on the screen
if(x==0)
{
setfillstyle(INTERLEAVE_FILL,RED);
bar(100,100,20,20);
}
else
if(x==1)
{
setfillstyle(INTERLEAVE_FILL,BLUE);
bar(100,100,20,20);
}
}
};
int main(void)
{
/* request autodetection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy, i;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) { /* an error occurred */
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(0); /* terminate with an error code */
}
int x;
test object;
for(int i=0;i<20;i++)
{
cout << "Enter 0 for red, 1 for Blue: ";
cin >> x;
object.setX(x);
}
//getch();
/* clean up */
closegraph();
return 0;
}
/*条形图示例*/
#包括
#包括
使用名称空间std;
#包括
#包括
#包括
课堂测试
{
私人:
int x;
公众:
测试()
{
}
int getX()
{
如果(x==0)
{
CUT请帮助,我急切地等待它可以减少这到MVCE?有许多调试器的C++。你可能需要了解一个。作为一个NoOB,什么是MVCE?