C++ function for a Perl guy

Software

C++ and Perl programming tomes, photo by Thomas Guest on Flickr

Feeling a bit homesick for Perl with all this C++ I’ve been writing of late, so I did this. It even forces me to put a newline just like my beloved Perl print function.

#include <iostream>
void print(const std::string message) {
   cout << message;
}

Now that I think about it, we could even bring a touch of home to my Ruby side:

#include <iostream>
void puts(const std::string message) {
   cout << message << endl;
}

I giggled incessantly when writing these, due perhaps to sleep-deprived, broken-ankle, exam-anxiety induced state.

Alternatively, I could have just done this:

#include <string>
#include <stdio.h>
void print(const std::string message) {
   printf(message.c_str());
}

But we all know how much C++ folks love when we mix in C stuff that has a C++ equivalent. I think I’ll stop now. #fallsasleep

Photo by Thomas Guest on Flickr.

Author bio and support

Me!

Ruben Schade is a technical writer and infrastructure architect in Sydney, Australia who refers to himself in the third person in bios. Hi!

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite bespoke cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or send a comment. Thanks ☺️.