In case you get an error code 6 from VS 2019, check that you have installed all the required tools, given by the docs:
Verify the tools below are installed:
- C++ profiling tools
- C++ AddressSanitizer
- Windows 10 SDK (10.0.18362 or Newer)
- Unreal Engine installer"
You can check by open “Visual Studio Installer” and go to the tab “Workloads” and then select “Desktop Development with C++” (naming may be a little bit different).
In my case Windows 10 SDK (10.0.18362 or Newer) was not installed by default when I installed VS 2019.
I just had to install the Windows 10 SDK and then I restarted my computer. Also, check that you have enough disk space in your C:/user/username/AppData/UnrealEngine (or just C:/ drive)
After doing this, I was able to setup a fresh (empty) C++ project in UE 5.1.
Hope this helps.