There are, in fact, some predefined build scripts, and it is relatively straightforward to create your own. These are known as compiler plugins or scripts, and live in the compiler directory of runtimepath.
You can switch to a compiler with the :compiler command, or by setting makeprg and errorformat (which is what most of these scripts do).
You then build ...
Yes, there is a way to build the file based on its file types. No, there is no predefined build script to build a script, you need to write it yourself, or look it up on the internet.
One way is to use autocmd to define a shortcut to run the build command for your current file:
autocmd FileType cpp nnoremap <F9> :!g++ -Wall -Wextra -std=c++...
The error you are seeing looks more like a Bash error than a Vim error. For example, here is what I get when I run your command from Bash:
$ filetype plugin indent on
-bash: filetype: command not found
Note that error identifier (i.e., EXXX) characteristic of Vim error messages does not appear in the output. Here is what I get when I try to run an invalid ...