If the file is named file.cpp or file.c, in the vim command mode just type in:
The first command compiles file abc.cpp to the executable file abc in the current directory. You can then execute it using the second command.
Alternatively, you could use something like :!g++ -g -Wall file.cpp -o file if you want to specify your own compilation options. (Anything more complex and you should be using a Makefile anyway).