I want to bind to a key a compile-and-run function to be able to compile my C++ single file programs and run them into a term/shell so I could give my variables values whenever I use
cin in my programs.
For example, in my Neovim config, I had this line:
autocmd FileType cpp nnoremap <F8> :w <CR> :vsp <CR> <C-w>l :term g++ % -o %< && ./%< <CR> i
I want to have something similar in Emacs. In Emacs, this line will be looking like so:
(define-key c++-mode-map (kbd "<f8>") #'compileandrun)
But I have no clue how the
compileandrun function will look.
edit 1: Here is a function I have tried
(defun compileandrun() (interactive) (compile (concat "g++ " (file-name-nondirectory (buffer-file-name)) " -o " (file-name-sans-extension (file-name-nondirectory (buffer-file-name))))) (term (concat "./" (file-name-sans-extension (file-name-nondirectory (buffer-file-name))))))
it only compiles the program but it dosen't run it .