You could try :set makeprg={\ g++\ %\ &&\ ./a.out;\ rm\ -f\ a.out;\ }.
Then use :make to compile and run your program.
Use :make | copen to run your program and open result in split window.
This will print compilation warnings too, you might want to turn errors to warnings or disable all warnings.
How to compile and execute the cpp file directly?
You could try
:set makeprg={\ g++\ %\ &&\ ./a.out;\ rm\ -f\ a.out;\ }
. Then use:make
to compile and run your program. Use:make | copen
to run your program and open result in split window. This will print compilation warnings too, you might want to turn errors to warnings or disable all warnings.