How to CCLog a CCArray

How to CCLog a CCArray
0.0 0


I dont know how to handle CCLog…

Can someone just let me know that How can I CCLog a CCArray Like —-
CCArray array;
NSLog("%", array);

CCLOG and CCDictionary/CCArray

No, you should loop CCArray and use CCLog to output each element.


like what would be the printed variable type?? What should I cast while on printing??

CCSprite balloon;
array = balloon->getChildren();

for (int i=0; icount(); ++i){
CCLog(“%???”, array ->objectAtIndex(i));


You can only use CCLog like printf, you should format the output.


Actually the problem is I dont know the format what CCArray actually includes with getChildren(). What should I print or CCLog if I dont now the variable type??
int a[10];
for (int i=0; icount(); **i){
Bt what is the type of:
CCSprite balloon;
array = balloon->getChildren;
for ;**i){
CCLog("*+%?+*", array ->objectAtIndex);

Can u illustrate with some example code


I see, you can not use CCLog if you don’t know how to format output.
It is not such powerful as NSLog.


how to use cclog to print an object,like ccsprite or something? in cocos2d, we can use clog("object = %", object); how to convert it to cocos2d-x?thank you


well you allways can use c++ templates
see simple example to print CCArray by T type class

// in header file 
     void printArray(CCArray* arr)
        CCObject *aGemIt = NULL;  
            T *aGem = static_cast(aGemIt);
            int col = aGem->getColNum(); 
            int row = aGem->getRowNum();
            CCLOG("col:%d row:%d",col,row);


then call this function like this :
Gem is class 

and to print CCDictionary

    void printDictionary(CCDictionary* dic)
        CCDictElement* pElement = NULL;
        CCDICT_FOREACH(dic, pElement)
            T* pSubClassObj = (T*)pElement->getObject();
            std::string oneStrKey = pElement->getStrKey(); 

and call it like this:

also this is for version stable version 2.1.5


There is PrettyPrinter class in cocos2dx 3.0 already.