Short Question ~How to append string with CCString?~


#1

Hi,

I am currently in the process converting an IOS game (using Cocos2d) to Android (using Cocos2d-X : cocos2d-2.0-x-2.0.4 @ Nov 02 2012).

My question is how to append a string similar to NSString?

I hope somebody can show me the proper way to append a string (CCString).

Thanks.

FaRHaN


#2

I’d use std::string like this:

CCString original; // assuming this is initialized somewhere

std::string str = original.getCString();
str += "Whatever you want to append";

original = str.c_str();

I know you’re porting a game from iOS, but you should avoid CCString whenever possible.
It’s easier to work with const char* and std::string.


#3

Yeah, using const char* and std::string classes are easier.

I just did something like tString->m_sString.append(“new_string”)

Thanks for the reply :slight_smile:


#4

I always forget the let you access the std::string field!
Your solution is better :smiley: