2014-08-29 81 views
2

我在执行代码块人们的首选代码块错误

#include <iostream> 
#include <graphics.h> 
using namespace std; 

int main() 
{ 
    int gd = DETECT, gm; 
    initgraph(&gd, &gm, "C:\TC\BGI"); 
    line(100, 200, 150, 250); 
    cout << "Hello world!" << endl; 

    return 0; 
} 

下面的代码,并在调试我的代码,此时停止在graphics.h中

int left=0, int right=0, int right=INT_MAX, int bottom=INT_MAX, 

我已经包括WinBGIm库。

回答

1

看起来像初始化图形驱动程序的问题。

IDE上以下代码的输出是什么?

#include <iostream> 
#include <graphics.h> 
using namespace std; 

int main() 
{ 
    int gd = DETECT, gm; 
    initgraph(&gd, &gm, "C:\\TC\\BGI"); 

    int errorcode = graphresult(); 
    if (errorcode != grOk) 
    { 
     cout << "Graphics error: " << grapherrormsg(errorcode) << endl; 
     return 1; 
    } 

    line(100, 200, 150, 250); 
    cout << "Hello world!" << endl; 

    return 0; 
} 
+0

我试着执行这段代码,它给出了同样的错误。 – Akash21795 2014-08-29 07:54:47

+0

@ Akash21795:你可以再次运行程序吗?这次用'“C:\\ TC \\ BGI”'代替'“C:\ TC \ BGI”'?确保路径'“C:\ TC”中有'BGI'目录 – Amit 2014-08-29 07:58:05

+0

我尝试更换路径“C:\\ TC \\ BGI”,并且程序终止于同一点。我确信路径。 – Akash21795 2014-08-29 08:18:34

0

您应该纠正graphics.h中这样:

int left=0; 
int top=0; 
int right=INT_MAX; 
int bottom=INT_MAX; 
1

您在graphics.h中在这条线设置right两次:

int right=0, int right=INT_MAX

更改line to this:

int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX