Trying Code Snippets in codepad.org

10 Mar 2011

codepad.org is an online compiler/interpreter for more than a dozen programming languages, such as C/C++, PHP, Perl, etc. It is very easy to use: write a few lines of code, hit the Submit button, and the execution result will appear at the bottom of the page.

It is a great tool for trying code snippets, learning language syntax, and communicate ideas. For example, I often forget how to use wchar vectors in C++. What I can do is grabbing The C++ Standard Library: A Tutorial and Reference and type the following code snippet in codepad.org:

#include <string>
#include <vector>
#include <iostream>

int main(int argc, char **argv)
{
    vector<wchar_t> wc(10);
    wc[0] = L'A';
    wc[1] = L'B';

    wc.resize(3);
    wstring ws(wc.begin(), wc.end());
    //wstring ws(L"This is a book\n");
    wcout << ws << endl;

    return 0;
}

After hitting the Submit button, you will see the following page:

codepad.org

Compare to writing prototype code snippets in Visual Studio and GCC, you don’t need to create a lot of temp source code files in your file system and you can try your ideas on any machine without installing any compiler/interpreter. It’s really another great example showing how cloud services can simplify our lives.