C++ function for a Perl guy

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.


Feedback and support

For comments and questions, tweet out to @Rubenerd_Blog, or email me at weblog at ruben schade dot com. Let me know if you don't want your comment posted. I also accept the following donations or referrals if you found something useful or fun. Thank you :).