Why graphics.h file doesn't work in dev c++ and code blocks?

graphics.h was a header file provided, along with a library, by some compiler bundles back in the eighties and early nineties.

It is not part of the C++ standard. It was something extra that some compiler vendors provided to customers, so they could do some graphics work on their computers. It was a library that worked on the computers of the day. DOS, basically.

This is the 21st century and there are many, many high-quality free graphics libraries, covering the many, many different operating systems that people use now.

There are even a few free graphics libraries that copy the functionality of graphics.h from the eighties/nineties, so that if you want to pretend to be programming for MSDOS in 1992, you can.