The gcc-8 package has been discontinued in the Ubuntu 22.04 and later default repositories, but it is still available in the Ubuntu 20.04 default repositories. To install the gcc-8 package from Ubuntu 20.04 in Ubuntu 22.04 run the following commands:
sudo apt update
wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-8/gcc-8_8.4.0-3ubuntu2_amd64.deb
wget http://mirrors.edge.kernel.org/ubuntu/pool/universe/g/gcc-8/gcc-8-base_8.4.0-3ubuntu2_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-8/libgcc-8-dev_8.4.0-3ubuntu2_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-8/cpp-8_8.4.0-3ubuntu2_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-8/libmpx2_8.4.0-3ubuntu2_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/main/i/isl/libisl22_0.22.1-1_amd64.deb
sudo apt install ./libisl22_0.22.1-1_amd64.deb ./libmpx2_8.4.0-3ubuntu2_amd64.deb ./cpp-8_8.4.0-3ubuntu2_amd64.deb ./libgcc-8-dev_8.4.0-3ubuntu2_amd64.deb ./gcc-8-base_8.4.0-3ubuntu2_amd64.deb ./gcc-8_8.4.0-3ubuntu2_amd64.deb
To install g++-8 in Ubuntu 22.04, first install the gcc-8 package from Ubuntu 20.04 in Ubuntu 22.04 as before and then run the following commands:
wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-8/libstdc++-8-dev_8.4.0-3ubuntu2_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-8/g++-8_8.4.0-3ubuntu2_amd64.deb
sudo apt install ./libstdc++-8-dev_8.4.0-3ubuntu2_amd64.deb ./g++-8_8.4.0-3ubuntu2_amd64.deb
Reply to the request in the last paragraph of the question to add an answer with detailed steps:
The instructions in the next four paragraphs are the same as the instructions in the above code blocks, but this section explains how those code snippets were generated in more detail.
.deb files from the official Ubuntu repositories of all currently supported versions of Ubuntu can be found at the Ubuntu Packages Search website. Search for the package name, select a distribution of Ubuntu from the Distribution: dropdown menu and click the Search button.

This brings up a package page specific to your distribution which in this case is focal. Click the focal link.
This brings up a new webpage. Scroll down a bit and click the amd64 link. This brings up a new webpage with download mirrors to download the package. Copy the link from a download mirror. I always select the first mirror which is "mirrors.kernel.org/ubuntu". Then change directories to your build directory and download the .deb file using wget.
Don't immediately install the .deb file that you downloaded without simulating the installation first with a command of the form apt install --simulate ./package1.deb ./package2.deb ./package3.deb
without using sudo . This command will not install anything. It will test for broken packages and unmet dependencies. If there are unmet dependency packages download them by following the instructions in the preceding two paragraphs, and continue iteratively until the apt install --simulate
command runs successfully without an error.