Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just started to study graphics. Since graphics.h is not included in codeblocks i made the required changes and made the below program. But i am getting warning: Deprecated conversion from string constant to char*

C++
#include<stdio.h>
#include<graphics.h>
int main()
{
   int gd=0,gm;
   initgraph(&gd,&gm,"");
   circle(100,80,20);
   getch();
   closegraph();
}


What I have tried:

I added the graphics.h and winbgim header filer in include folder. Added libbgi.a in lib folder. Added the path of this library file and "-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32" in linker settings.

Please let me know if i am missing any step here.
Thanks.
Posted
Updated 23-Aug-20 18:38pm
v2
Comments
Richard MacCutchan 8-Aug-18 6:50am    
You did not explain where that error message occurs, and I cannot see any references to strings or char* in the sample code.

You would be better switching to Visual Studio and using the more modern fully supported graphics of Windows GDI/GDI+.
Member 13922884 8-Aug-18 6:55am    
My apologies.The error message is displayed for initgraph ().

Pass NULL instead of an empty string. The reason you got this warning (it is a warning and not an error) is that you pass a string literal which is const by definition but the function parameter is not const (char *).

Note also that initgraph() and the other graphic functions belonged to the ancient Turbo-C/C++ compilers for MS-DOS. Using those nowadays via WinBGIm is not the best choice to learn graphics programming.
 
Share this answer
 
Comments
Member 13922884 8-Aug-18 8:53am    
Thanks. But it is also not working. Should i make all the changes again?
Jochen Arndt 8-Aug-18 9:27am    
Please define "not working".
Any compiler or linker errors?
If nothing happens during runtime, add error checks to your code inspecting the value of gd and/or using graphresult.

But again:
It is an ancient interface designed for MS-DOS. Think about using other interfaces instead of investing time to learn it and get it running on the shell of recent operating systems.
Member 13922884 8-Aug-18 9:39am    
Same warning as before.
Jochen Arndt 8-Aug-18 9:43am    
It is a warning and not an error. When not having enabled to treat warnings as errors, an executable file should be created.

However, it should not happen when using
initgraph(&gd,&gm,NULL);

Depending on the compiler you should also get another warning that main() is not returning a value.
Member 13922884 8-Aug-18 11:16am    
It is not giving warning now. But i am not getting the output and getting the run time error.
"Visual Studio Just-In-Time Debugger

An unhandled win32 exception occurred in Test1.exe [3992].
Just-In-Time debugging this exception failed with the following error:
No Installed debugger has Just-In-Time debugging enabled. In Visual
Tools/Options/Debugging/Just-In-Time.

Check the documentation index for 'Just-in-time debugging, errors' for
more information."
I followed https://erainnovator.com/how-to-include-graphics-h-in-codeblocks/ and I was able to use graphics.h in codeblocks. I hope this will resolve your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900