0
\$\begingroup\$

Mentioned in : How to prepare a game for localization?

It's a really good idea to use an actual string class and not just char * everywhere or you're going to be in a world of pain.

I currently use char * everywhere, and wondered if people could explain the benefits of a full string class, and the pitfalls of char *. Are there any good solid existing string classes to be recommended?

Not only in reference to localisation, but for any reason.

\$\endgroup\$
  • 1
    \$\begingroup\$ It's a good question - for StackOverflow.com . As currently worded, this has nothing to do with game development - localization is a fairly general concept. \$\endgroup\$ – Cyclops Aug 6 '10 at 13:44
  • \$\begingroup\$ It's also slightly subjective. \$\endgroup\$ – Ricket Aug 6 '10 at 13:47
  • \$\begingroup\$ Fair enough. Can someone close the question please? \$\endgroup\$ – Olly Aug 6 '10 at 13:49
2
\$\begingroup\$

You might get better answers in Stack Overflow, as the benefits of a string class apply to all programs, not just games.

But a great string class, of course, is std::string from the C++ Standard Library! It keeps track of the length of the string (rather than searching for a null character every time you call strlen). You can easily iterate the string and append to or modify it, unlike using char* and the str functions. And at any time, you can get a char* via the member "c_str", so you can adapt it pretty easily. Here are examples of usage of std::string which look pretty helpful in getting a feel for exactly what the class can do for you.

It's basically one step towards higher-level languages when you're manipulation a string rather than an array of characters.

\$\endgroup\$
  • \$\begingroup\$ Herb Sutter would disagree that std::string is great. :) \$\endgroup\$ – tenpn Aug 6 '10 at 14:29
  • \$\begingroup\$ What's so bad about std::string that Sutter says? I find it great. \$\endgroup\$ – The Communist Duck Aug 6 '10 at 14:31
  • \$\begingroup\$ Can't find the reference, but he thinks that there's too many member functions that should be non-member non-friend and/or templated generic functions. \$\endgroup\$ – tenpn Aug 6 '10 at 15:09
  • \$\begingroup\$ Here's the Sutter reference: herbsutter.com/2008/04/07/… \$\endgroup\$ – Cyclops Aug 6 '10 at 17:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.