Python vs. C++ round 1
Got the skeleton for my game programming assignment all done. Now I'm implementing each rotational factor and have the XYZ decomposition done.
Boy, I'm spoiled by all this Python I've been doing. Man, what a pain C++ about the simple things like integer to string and back. I could use boost's lexical_cast, but I don't want to make it harder for my teacher to grade it.
Also, what a pain in the neck it is to generically select an input or output stream (including stdin or stdout). Like most things, in Python it is ridiculously easy:
if beetle_battle:
out = sys.stdout
else:
out = open("output.txt", "w")
print >>out, "And now for something completely different!"
Now in C++:
beetle_battle = true;
streambuf* fb = 0;
if ( beetle_battle )
fb = cout.rdbuf();
else {
ofstream* ofs(new ofstream);
filebuf* ofb = ofs->rdbuf();
ofb->open( filename.c_str(), fstream::out );
fb = ofb;
}
ostream outfile(fb);
posted on February 8, 2008 at 8:06 a.m.