It turns out that adding code snippets into WordPress is somewhat difficult and, surprisingly, there are no good “official” solutions for what must be a fairly common need. Recall that a WordPress page is just HTML markup, so you have to suitably encode a snippet and embed everything inside the right HTML tags to avoid the snippet being interpreted as code, not text. Most wiki software programs provide macros and functions that take care of the low level details of this process, but WordPress does not.
However, you can go to the WordPress site and hunt for plugins that will do the trick for you. After a bit of research, it seems that the Code Prettify plugin, which is based on the Google Code Prettify library, is the consensus choice for this sort of work.
All you have to do is download and install the plugin from the WordPress dashboard and thereafter all snippets included within <pre> and <code> tags will be displayed correctly.
For example:
int main() { std::cout << "Hello world" << std::endl; return 0; }