Skip to content

Comment on Cling: Running C++ in an interpreter

Comments

I just keep a fixed .cpp file with a bunch of common includes and directives, and alias the g++ command to link to common libraries, so my workflow goes:

> vim temp.cpp

> g++ temp.cpp

> ./a.out

Very similar to my process with Python, actually. Every time I use the REPL for some experimenting, the code ends up outgrowing it and I have to stuff it in a file anyway, so I may as well cut out the middleman to begin with. YMMV.

I too put the code in a file even in Python, but REPL is still valuable. I use "python -i" which runs your code (defines functions, classes, etc.) and then stop, and put you in that environment. This is very useful. It seems Cling could be used the same way: .x command.

I must be reading the wrong Python tutorials. Thank you for this

If you don't need any special compiler flags, it's even simpler:

    make temp
    ./temp
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.