c++arraysstringcocos2d-xcocos2d-android

How to Create a string array in cocos2d-x 3.17v


I am new to Cocos2d-x I am using 3.17v i am have some trouble i am not able to create a string in cocos2dx i want to create a string array for storing sprite file names

String* cars[5];

I Tried this it is not working and an error is occur saying

type 'String' is deprecated


Solution

  • I would suggest that you start using standard types such as std::string, and not cocos2d::String. Also, for arrays, you can use std::vector.

    std::vector allows you to add objects of a certain type including duplicates.

    std::vector<std::string> stringVector;
    stringVector.push_back("my string");
    

    There are multiple ways to construct/initialise/use std::string and std::vector objects, but you can easily find information about this all over the internet or in the documentation links I've provided above.