Tero Karvinen - Articles - Downloads - Courses - Contact

Table of Contents

Tero's C++ Scripting - cppt

Tero’s C++ Scripting lets you write a script


cout << "Hello World!" << endl;

and just run it

$ chmod a+x hello.cc
$ ./hello.cc
Hello World!

Download Tero's C++ Scripting - Syndicate


Tero’s C++ Scripting

C++ as a Scripting Language

Syntax of C++ is very clear if you compare it to scripting languages such as perl and bash. The best examples are if and test constructions in bash, or function (sub) definitions in perl and bash.

C++ scales well. Probably most programs in the world start with “hello world”. But they grow. If you start with C++, you can keep improving the same program instead of starting from scratch when your prototype is ready.

C++ is precise. It requires you to declare your variables and it does strong typing. With PHP, you always get a program if you just write something - but not necessarily the program you were thinking of. With C++, typos give an error, not a program that does something else.

C++ can be easy. Using C++ constructs and not C, you can create understandable, simple and short programs. With convience functions (see “Future” below), it can be even easier. For example, vectors and strings are easy to use. C++ is a full featured language, so it can give you enough rope to hang yourself with. Resist the temptation of the dark side of pointers and char arrays!

Download and Install

Download cppt-latest.tar.gz. (Beta version)


$ tar -xf cppt*.tar.gz
$ cd cppt*

Install requirements. This command is for Ubuntu Dapper, substitute installation command with a different one if you are using another distribution.

$ sudo apt-get install g++ libboost-doc
$ sudo apt-get install libboost-regex-dev libboost-filesystem-dev


$ make


$ sudo cp cppt /usr/local/bin/


Writing Your First Script

If you have ever written a shell script in bash, you probably know this already.

Write a program to a text file

$ nano foo.cc
cout << "Hello Tero's C++ Scripting World!" << endl;

Save it with ctrl-X y enter.

Make it runnable

$ chmod a+x foo.cc

Run it

$ ./foo.cc
Hello Tero's C++ Scripting World!


Provide convience functions to do typical script things.

string contents = readFile("tero.txt");
writeFile("tero2.txt", "Foo bar this is some text");
string cmd="ls /etc/";
systemExec(cmd+">output.txt"); // C++ string support
cout << regReplace("Tero's C++ System", "S.*m", "Scripting") << endl;

If you need those functions now, you can view the source code of Tero's C++ Scripting. Remember that GPL license requires you to use the same license for your work and mention the source if you copy any code.



Does this run on Mac? BSD? Windows? If you run an operating system other than Ubuntu Linux, tell me this works on your system.

Packagers Wanted

You can help by packaging Tero’s C++ Scripting for your distribution. Most wanted are 1) Ubuntu or Debian 2) Fedora or Redhat 3) Mandriva, SuSe, Gentoo, anything else.

When you package

  1. Optional: Email me what distribution you are working on, I’ll keep it reserved (tell anyone asking) for two weeks
  2. Publish your package on your homepage - so that it’s immidiately available
  3. Email me, I’ll copy it to Tero’s C++ scripting homepage or link to it
  4. Submit it to distribution of choice.

Links and Syndication

Freshmeat page of Tero’s C++ Scripting http://freshmeat.net/projects/cppt/.


Rate in Freshmeat

Digg this

Submit to Slashdot


I’m looking forward to hearing from you!

You can use the quick feedback form to send me feedback or email: karvinen+cppt at iki.fi

Last modified: 2007-09-15. Permanent url: http://www.iki.fi/karvinen/cppt.html

Tero Karvinen www.iki.fi/karvinen - Top - Validate HTML - Validate CSS