Using C++ commands directly from command line

c++

Solution

There is cling which is an interactive C++ shell. I haven't used it but it may fit your needs.

Here is a bit of a more expanded response: it took me a while get cling built, primarily because I wasn't following instructions exactly and set up the source tree to include things it should have included. Here are the steps I used to build and install cling (building a release version didn't work for me):

svn co -r 191429 http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn co -r 191429 http://llvm.org/svn/llvm-project/cfe/trunk clang
git clone http://root.cern.ch/git/cling.git
cd ..
cat tools/cling/patches/*.diff | patch -p0
./configure --enable-targets=host --prefix=/opt/cling
mk -j8
sudo - make install

After this, I got a C++ shell. Of course, my first interaction wasn't entirely successful because the cling page says that it includes some headers. I had assumed that it would surely include `<iostream>` but that wasn't the case. Here is a simple interaction that works, though:

$ /opt/cling/bin/cling 

****************** CLING ******************
* Type C++ code and press enter to run it *
*             Type .q to exit             *
*******************************************
[cling]$ #include <iostream>
[cling]$ std::cout << "hello, world\n";
hello, world
[cling]$ #include <iterator>
[cling]$ std::copy(s.begin(), s.end(), std::ostream_iterator<char>(std::cout));
hello, world
[cling]$ .q

Problem

I wanted to ask Is there any way by which you can simply use 'std::cout << "Hello world";' directly from command line. As in like if you have python installed, ``` $python print 'Hello world' Hello world ``` Can something like this be done for C++ by any means?

Original source