Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя cacophonix

Автор cacophonix, 11 лет назад, По-английски

for running testcases in vim if first copy the test cases in a text file called 'in' and press F6

which runs the code by taking input from the 'in' text file.

i have

map <F6> :w<CR>:!g++ % -g && (ulimit -c unlimited; ./a.out < in) <CR>

in my .vimrc file.

IS IT POSSIBLE TO RUN THE CODE BY TAKING INPUT FROM THE SYSTEM CLIPBOARD ?

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
11 лет назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

In a platform-dependent way, yes. xclip (with some parameter I don't remember) in Linux and pbpaste in Mac OS can output the contents of clipboard. So for example in Mac OS adding 'pbpaste > in;' before ./a.out should do the trick.

»
11 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

You can use this way:

map <F6> :call TestIt() <CR>
function TestIt()
  let l:test = substitute(@+, "'", "", "g")
  let l:file = @%
  write
  let l:output = system("g++ '".file."' -g && (ulimit -c unlimited; echo '".test."' | ./a.out)")
  echo l:output
endfunction

I tried it on Linux and Windows, so it should work.

UPD: local variables and sanitize string

»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I used this two in vimrc:

autocmd filetype cpp nnoremap <F6> :w <bar> exec '!g++ -g -Wall -std=c++0x '.shellescape('%').' && ./a.out' <CR>
autocmd filetype cpp nnoremap <F7> :w <bar> exec '!g++ -g -Wall -std=c++0x '.shellescape('%').' && ./a.out < d.in' <CR>

Is good to activate warnings with -Wall because several warnings are truly errors and may become difficult to find it.