C++ interpreter / console / snippet compiler
Asked Answered
M

6

7

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: 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$.

Mangrum answered 27/7, 2009 at 16:11 Comment(1)
Not a good way of learning C++, IMHO. The things such a system would hide from you are things you really need to know and fully understand.Emission
E
13

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).

Exo answered 27/7, 2009 at 16:22 Comment(1)
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.Mangrum
T
2

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

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

Teleview answered 27/7, 2009 at 18:5 Comment(0)
R
1

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/

Regen answered 14/10, 2009 at 19:21 Comment(0)
C
1

Cling (interactive C++ interpreter, built on the top of LLVM and Clang libraries): https://root.cern.ch/drupal/content/cling

Caves answered 21/3, 2015 at 12:41 Comment(0)
L
0

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.

Laclair answered 27/7, 2009 at 16:24 Comment(0)
Q
0

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.

Quake answered 28/7, 2009 at 13:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.