Fixing Chinese Garbled Text in Code::Blocks

Code::Blocks is a C/C++ IDE that I personally like to use, but I kept running into one problem: with Code::Blocks, I couldn’t use Chinese at all. Strings couldn’t contain Chinese, and even comments couldn’t. I originally thought it was a bug in the program itself, but a fellow user reminded me that it was actually a default encoding issue! ...

September 3, 2011 · 1 min

[C++] Sorting with the STL's Built-in sort() Function!

Sorting is something everyone who learns programming has to master, because a lot of data processing depends on it. Many programming languages include sorting functions built in, so developers can use them easily. But I don’t think many people know that C++ also has a built-in sorting function! ...

August 25, 2011 · 2 min

1A2B Code Explained

This was an assignment from my teacher: design a 1A2B guessing game. Before this class, I always thought 1A2B was hard to write. After the class, I realized it wasn’t hard at all. I was just too much of a homebody and didn’t even know the rules of 1A2B…. ...

July 8, 2011 · 3 min

Shuffle Algorithm (Swap Method)

The shuffle algorithm is a way to generate random numbers that never repeat. For example, suppose you need to generate ten random numbers, and all ten must be “unique.” Many people’s first instinct is to call the rand function to get a random value, store it in an array, and compare it against the numbers already in the array. That method is simple, but its performance is very poor. The shuffle algorithm introduced here is worlds apart from that approach in terms of performance. The principle behind the shuffle algorithm is actually very simple: first store the numbers in an array, then scramble them. ...

June 5, 2011 · 3 min

wxDevC++ - The C++ IDE Every Dev C++ Fan Needs to Know About

A lot of people who learn C++ actually start with Dev C++. VC++ is convenient for beginners, sure, but you can’t learn standard C (ANSI C) with it, because VC contains far too many functions that belong to .NET — compile that code with another compiler and you’ll run into trouble. So beginners generally go with Dev C++ or Code::Blocks. Unfortunately, Dev C++ hasn’t been updated for several years, and it no longer supports many newer features. Code::Blocks, on the other hand, has poor Chinese support: if there’s Chinese anywhere in your code you’ll run into problems, and that includes not being able to use Chinese in comments. The one I want to recommend here, wxDev C++, actually carries on Dev C++’s characteristics while adding some new features, unlike Dev C++ which has no end of problems… So if you’re comfortable with Dev C++, I’d suggest giving wxDev C++ a try, because it’s almost identical to Dev C++! As for me, I’ll just keep using my Code::blocks~ ...

May 18, 2011 · 2 min

How to Convert a Decimal Number to Binary?

I expect someone will say this article is too simple again once I finish writing it... Without further ado: this week, our teacher gave our class a problem, which is how to convert a decimal number to binary. If you do it with math, it isn't hard. Just use short division and take the remainders. ...

April 16, 2011 · 2 min

Printing Triangles: Top-Left, Bottom-Left, Top-Right, Bottom-Right

These were some examples my programming teacher used when teaching loops in class. I think the problems themselves aren't hard, but they're great for practicing loops and training your reaction speed. Also, my VB skills have gotten a lot rusty... So I'm attaching the C++ code for everyone to look at. Go study it yourselves~ ...

March 21, 2011 · 1 min

[C++] How to Do Exponentiation and Square Roots (sqrt, pow)

In some programming languages, you can do exponentiation directly with the ^ operator. But while working on a problem, I found out that in C++, you have to use the pow function to do exponentiation. This article introduces two functions: pow, which does exponentiation for you, and sqrt, which takes square roots. ...

March 18, 2011 · 1 min

[C++] Reversing Numbers and Strings (Applications: Type Conversion, String Handling, Loops)

This is a fairly simple problem: it just reverses a number or a string. For example, input "linroex" and the output is "xeornil", or input 123 and get 321. The solution isn't hard. In C++, you can access a string like an array, so we set up a loop whose end value is the length of the input string. On each pass, we move the last remaining character of string X to the first position of string Y. When the loop finishes, the reversal is complete. ...

March 6, 2011 · 2 min

[PHP] [C++] A Concise Syntax for Explicit Type Casting

PHP and C++ have a very convenient way to cast types. You don't have to memorize a long list of conversion functions. You just put the target type in parentheses in front of the value. However, this approach seems to have some problems, though I'm not really sure what they are XD...

February 15, 2011 · 1 min