Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Mentioned in : http://gamedev.stackexchange.com/questions/679/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.

share|improve this question
1  
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. –  Cyclops Aug 6 '10 at 13:44
    
It's also slightly subjective. –  Ricket Aug 6 '10 at 13:47
    
Fair enough. Can someone close the question please? –  Olly Aug 6 '10 at 13:49
add comment

closed as off topic by Michael Barth, Tetrad Aug 6 '10 at 14:34

Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

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.

share|improve this answer
    
Herb Sutter would disagree that std::string is great. :) –  tenpn Aug 6 '10 at 14:29
    
What's so bad about std::string that Sutter says? I find it great. –  The Communist Duck Aug 6 '10 at 14:31
    
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. –  tenpn Aug 6 '10 at 15:09
    
Here's the Sutter reference: herbsutter.com/2008/04/07/… –  Cyclops Aug 6 '10 at 17:14
add comment

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