views:

639

answers:

5

Hi,

I am looking for a program where I can enter a C++ code snippet in one window, press a button, and get output in another window. Compilation should somehow be hidden behind the button. On a per-snippet basis would be fine, full interactive probably asking too much. It should run under Linux/Unix. Main use case would be learning/testing/short debugging, etc.

Related stuff I found:

-- the Reinteract project for python (which i'm told sage has features similar to)

-- the same thread for C# here: http://stackoverflow.com/questions/47537/c-console

-- the CINT interpreter from the CERN ROOT project (which may be close, but maybe there are more comfortable apps around)

-- some programs called Quickly Compile or Code Snippet, which are M$.

+5  A: 

http://codepad.org/ works nicely for this purpose. By default, it will run what you paste when you hit submit and display the result (or any errors you might have).

Evan Teran
This looks nice :) It seems to be more interactive after setting up an own project. It creates a new node after every change though. But still really neat, especially the multi-language.
A: 

I would do it like this:

  • Capture the 'snippit' as text
  • Create a.cpp with the following:

    int main() { snippitCode(); return 0; }

    void snippitCode() { // INSERT SNIPPIT HERE }

  • Use 'exec' to launch a compiler and pipe the output to an output file.

  • Use 'exec' to run the application and pipe the output to an output file.

In the 'output' window, you can run 'tail -f' on the output file to continuously update when new output arrives.

Kieveli
Weird 'code block' within a list item messes up the code.
Kieveli
+1  A: 

Dinkumware has a page for this AND you can choose the compiler

http://dinkumware.com/exam/default.aspx

pgast
A: 

Just configure your code editor to compile and run your code snippets.

Most code editors have the capability of 'sending' the current buffer/file to an external tool. I configure one editor key binding to compile the current buffer, and another key binding to execute whatever was last compiled (actually to run whatever has the same base filename as the current buffer with an '.exe' extension). My experience is with Windows, but the same or similar can be done on Unix/Linux.

Then it becomes one keystroke to compile and another to run what I jut compiled. This could also easily be just a single keystroke to compile & run, but I have several key bindings set to compile using various different compilers. That way I can easily test snippets using the latest MSVC, MSVC 6, MinGW GCC, Comeau and Digital Mars compilers to check for differences.

Michael Burr
A: 

Do something like this ? test a C# snippet code by just copying it to the clipboard and then type csc.exe: http://reboltutorial.com/blog/redirect-shell-to-rebol-console/

Rebol Tutorial