Avoid public variables, except for classes that are essentially C-style structs. It's just not a good practice to get into.
Once you've defined the class interface, you might never be able to change it (other than adding to it), because people will build on it and rely on it. Making a variable public means that you need to have that variable, and you need to make sure it has what the user needs.
Now, if you use a getter, you're promising to supply some information, which is currently kept in that variable. If the situation changes, and you'd rather not maintain that variable all the time, you can change the access. If the requirements change (and I've seen some pretty odd requirements changes), and you mostly need the name that's in this variable but sometimes the one in that variable, you can just change the getter. If you made the variable public, you'd be stuck with it.
This won't always happen, but I find it a lot easier just to write a quick getter than to analyze the situation to see if I'd regret making the variable public (and risk being wrong later).
Making member variables private is a good habit to get into. Any shop that has code standards is probably going to forbid making the occasional member variable public, and any shop with code reviews is likely to criticize you for it.
Whenever it really doesn't matter for ease of writing, get into the safer habit.
m_
instead of_
. – Venavenablem_
in Javascript and Java. People seem to forget these are the least inelegant solutions to C++ inconveniences (for example, in Java, fields and methods can have the same name) – Hagi