-1

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

  • Use the standard [`std::string`](http://en.cppreference.com/w/cpp/string/basic_string) instead? And make an array of *strings*, not an array of *pointers* to strings. – Some programmer dude Jun 19 '18 at 06:52
  • Deprecated means it should not be used. Code and API's do evolve, and some caracteristics do get deprecated in favor of new ways to do the things. Check https://stackoverflow.com/questions/2941900/is-it-wrong-to-use-deprecated-methods-or-classes-in-java – Cleptus Jun 19 '18 at 07:03

1 Answers1

1

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.

Boby
  • 856
  • 7
  • 9