Q:

Adding a horizontal rule between caption and lstlisting inside a tcolorbox

I have example listings for a book.

I
want to add a horizontal rule between the caption and the listing.
I tried to use the \hrule command, but it doesn't work.

A:

You can use the \hrule command from the booktabs package.
\documentclass{article}
\usepackage{booktabs}