PDA

View Full Version : Giúp khắc phục lỗi Graphic.h



ndp1007
18-02-2009, 05:50
Code này khi chạy VS C++ thì báo lỗi
"Cannot open include file: 'graphics.h': No such file or directory"
là sao vậy các bạn
Vậy để tạo file Graphic.h thì phải làm sao và để nó ở đâu.


#include <graphics.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h>

int main(void)
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");

int maxx = getmaxx(), maxy = getmaxy();
char msg[] = "Hello !";
int msgwidth = textwidth(msg);
int msgheight = textheight(msg);
int x = maxx + msgwidth;
int y = (maxy - msgheight) / 2;
int dx = 5;
char ch = 0;

do
{
setfillstyle(SOLID_FILL,0);
bar(x, y, x + dx + msgwidth, y + msgheight);
outtextxy(x, y, msg);
x -= dx;

if (x < -(dx + msgwidth))
{
x = maxx + msgwidth;
}

if (kbhit())
{
ch = getch();
}

delay(200);
}
while (ch != 27);

closegraph();
return 0;
}

ptaminh
18-02-2009, 08:28
Code này khi chạy VS C++ thì báo lỗi
"Cannot open include file: 'graphics.h': No such file or directory"
là sao vậy các bạn
Vậy để tạo file Graphic.h thì phải làm sao và để nó ở đâu.



Đơn giản là VS C++ không hỗ trợ thư viện này, muốn lập trình graphics thì có thư viện gdi của windows, hoặc gdi+ (phải tự cài thêm).

Nguyen Khoi
18-02-2009, 08:34
#include <graphics.h>

Vi ban dung VS C++ nhung lai include thu vien cua borland C --> "Cannot open include file: 'graphics.h': No such file or directory".

ndp1007
18-02-2009, 13:48
Vậy phảo làm sao hở máy "Pác" chỉ em chi tiết đi...thank lot

Nguyen Khoi
18-02-2009, 15:17
Vậy phảo làm sao hở máy "Pác" chỉ em chi tiết đi...thank lot

Neu ban dung thu vien graphics.h thi ban ra ngoai cua hang tim mua dia Borland C (3.0 gi do tui nho khong ro) ve cai vao la chay duoc a.

ndp1007
19-02-2009, 13:04
Mình chạy trên Bordland C 3.1 củng lỗi luôn

nguyenduyy
19-02-2009, 23:49
Mình chạy trên Bordland C 3.1 củng lỗi luôn

lỗi do câu lệnh này initgraph(&gdriver, &gmode, "");

nếu dùng Borland c thì phải có đường dần đến thư mục BGI
ví dụ như
initgraph(&gdriver, &gmode, "D:\\BORLANDC\\BGI");

ndp1007
21-02-2009, 14:04
lỗi do câu lệnh này initgraph(&gdriver, &gmode, "");

nếu dùng Borland c thì phải có đường dần đến thư mục BGI
ví dụ như
initgraph(&gdriver, &gmode, "D:\\BORLANDC\\BGI");

Bạn chỉ đúng đó,chạy được rùi ,cảm ơn nhiều nha..................

duc_hieu2811
15-10-2009, 11:53
các bác cho em hỏi.Em dùng cái borlandc c++
em cho chạy chương trình sau mà nó cứ báo lỗi undefined symbol _closegraph in modume VEBANHXE.CPP
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<dos.h>
#include<math.h>
#include<stdio.h>
#pragma warn -pro
float t=0.0;
float x,y;
void vebanhxe()
{
int x1,y1,x2,y2,x3,y3,x4,y4;
circle(x,y,20);
x1=x-20*cos(t);
y1=y-20*cos(t);
x2=x+20*sin(t);
y2=y+20*sin(t);
x3=x-20*cos(t+90);
y3=y-20*cos(t+90);
x4=x+20*sin(t+90);
y4=y+20*sin(t+90);
line(x1,y1,x2,y2);
line(x3,y3,x4,y4);
}
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
line(0,321,getmaxx(),321);
x=100;
y=300;
while (!kbhit())
{setcolor(YELLOW);
vebanhxe();
delay(10);
setcolor(BLACK);
vebanhxe();
t+=0.05;
x+=1;
if(x>getmaxx()+20)
x=0;
}
closegraph();
}