#include<graphics.h>
#include<conio.h>
#include<iostream>
using namespace std;
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "c:\\TC\\BGI" );
cout<<"Please Enter to continue..."<<endl;
getch();
closegraph();
return 0;
}
All other programmes are running fine on my Codeblock 13.12, but when I run a simple graphic programme compiler crashes giving pop up window that says:
"graphic.exe has stopped working window is checking solution".
It also giving a warning message on compilation:
warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
How to resolve it?It is due to turbo C.
It is due to turbo c.
Turbo c/c++ is ancient and didn't conform any standards. There are no such header files like conio.h or graphics.h for any modern c++ compilers.
Your codeblocks IDE most probably uses the GCC toolchain by default, which doesn't provide these headers.
You should lookup for more modern 3rd party libraries for handling graphics and raw keyboard input (e.g. something like SFML). The c++ standards have no notion about such stuff so far.
For Graphics Programming In C You Need To Install Codeblocks-EP Version. Download From Here http://codeblocks.codecutter.org/setup.exe
Install And Then Go File>New>Project>Winbgim project>GO>>Add Console>>NEXT . Give Project Name,location path And Click Finish. Now Again File >New>Empty File
Write Your C graphics Code>> Build And Run.
This Codeblocks has pre installed built in graphics libraries. So You need not to add anything.
Related
I already have graphics.h(and relevant files in MinGW ) but the programs are not working, because after build and run, I get required text output on output window but not the corresponding graphics
because program_name.exe stops working.
I already have searched all over the internet, StackOverflow is my final hope.
I have been doing competitive programming in c+ +, just tried to get into graphics with c++ in code blocks.
#include <graphics.h>
#include <iostream>
using namespace std;
int main()
{ cout<<"a";
int gd= DETECT,gm ;
char driver[] = "";
initgraph(&gd, &gm, driver);
//initgraph(&gd,&gm," ");
circle (100,100,100) ;
getch();
closegraph();
return 0;
}
This is VERY retro. In order for this to even come CLOSE to working you will need to create an MSDOS virtual machine under something like VirtualBox, install DOS 6.2 or similar, install the Borland BGI, Borland C++ 5.02 and then you MIGHT get it to work. Failing that, you could just find an old IBM PC and install DOS on it along with everything else above. Have fun!
I am using Code::Blocks 16.01 for coding in C++ every code runs properly without showing any problem or error. But ever I runs a graphics program it shows a pop-up window with message circle.exe has stopped working(circle.cpp is the name of my program)(had already copied graphics.h ,winbigim.h and libbgi.a and also corrected the line 302 error in graphics.h and had also had done the linking work).
code that i am using is:-
//circle.cpp
#include <graphics.h>
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
circle(100,100,50);
getch();
closegraph();
return 0;
}
it shows a pop-up window with message circle.exe has stopped working.
But when ever I run the same code in Turbo C++ it runs without any problem/error.
What should I do?
It is because the BGI graphics expect powers that modern systems don't give out willy-nilly anymore.
To use the old library, your options are:
(1) Run your program in DosBox, and x86 emulator
Dos Box
The other option are to get a modern graphics library, like SDL(It's better way and I suggest you).
I'm a highschool student, who have only ever coded in Turbo C++. I have no idea how IDEs work, I installed Qt Creator to start learning GUI programming but I can't even get it to run a simple C++ code. I doesn't know what files to include.
NOTE: I'm a total newbie.
The tutorials I found on YT are confusing and not clear. I have no idea why this is happening. This is my code:
#include<IOSTREAM.H>
#include<CONIO.H>
void main() {
clrscr();
cout << "Hello World!";
getch();
}
I did build all, then run but I got this Issue:
No rule to make target `all'. Stop.
Screenshot of Qt Creator
clrscr() is Windows specific (or is it Turbo C++ specific - I forget), in any case; don't use it.
cout should be std::cout.
you should include "iostream" not those obsolete ".h" versions (besides, the header names are lowercase, not uppercase).
void main is not valid. main always returns int.
Note: these bugs have nothing to do with Qt nor qtcreator. They are just, plain and simple, bugs in your code. Read Qt documentation and try out some tutorials.
I am having trouble using graphics.h in code blocks.
I have installed winbgi.
Edited 302nd line.
Linked lib file and all that stuff is done. So, I don't have any error regarding graphics header file.
But whenever I run/build any code involving graphics functions, windows gives an error ".. has stopped working". How to fix this?
I am using Codeblock v16. Windows 7ultimate - 64bit.
Here is my code:
#include<graphics.h>
int main() {
int gd = DETECT,gm;
initgraph(&gd, &gm, "c:\\tc\\bgi");
line(80, 100, 100, 100);
getch();
//return 0;
}
screenshots:
[SOLVED]
Unfortunately, it was all about 'bad' library files. I think, many have downloaded same(with bug) files in internet. Now I have bug-free files shared in google drive. And also Code::Blocks 16.01 (latest version)
Here's link. Replace old files with these new ones.
I have explained those steps and few FAQs here on this topic with links and test codes.
use of DosBox for emulate MS-DOS in Windows7.
just i can help you with bellow link, its useful.
See : How use of DOSBox in Windows 7
I am trying to write a program that should use a C library (the LIS library) in a C++ program. There seems to be a problem with the creation/initialization of struct objects.
When I run the example program on the wikipediapage: http://en.wikipedia.org/wiki/Lis_%28linear_algebra_library%29 it runs like a charm, but of course that is compiled as a C program.
In my C++ code I do it as follows:
#include "stdafx.h"
#include <iostream>
extern "C"
{
#include "lis.h"
#include "lis_config.h"
LIS_MATRIX A;
}
using namespace std;
int main(LIS_INT argc, char* argv[])
{
lis_initialize(&argc, &argv);
lis_matrix_create(LIS_COMM_WORLD, &A);
getchar();
return 0;
}
When I run this code, it gives me an access violation at the line lis_matrix_create. It seems as though A has an memory address, its data members (LIS_MATRIX is defined as a struct in Lis.h) have not been initialized, and therefore their addresses are NULL.
Could you please tell me how to create the LIS_MATRIX in such a way that I can use it like it is done in the example code on the wikipedia page?
Thank you in advance!
In reply to Adam and Ross Ridge:
I use visual studio 2013 on Windows 7 64 bit. The manual of the Lis library states that it is compatible with the Visual Studio 2008, 2010 and 2012 compilers, and also with gcc 3.4 and 4.4 and some IBM, Intel and PGI C++ compilers, I hope Visual Studio 2013 will not be a problem.
Also, in this code, if I take out the 'extern C' block, and include 'stdio.h' instead of iostream, it runs without problems (so I guess that it means the C compiler is used?). The minute I also include iostream, the access violation start.
You are including
lis_config.h
after
lis.h
wich is per se an error(you have to include it before). Also if you touched anything in lis_config you have to rebuild the whole library (using most same compilers flag of your project, for example "-msee2" if you used SSE2). Before rebuilding just swap headers only to see if that is enough..
A few more words: a library can easily detect headers included in wrong order, make a ticket to lis developers for that.