I have a static array which I only need to update in certain areas.
char* MapIds[5000] = { "Northeast Asia","Hanyang","Pusan","Pyongyang","Shanghai","Beijing","Hong Kong" /* 4999 more stuff */ };
I have a mapName which is a JSON Object it can give a String which I convert to a char* using c_str();
I want to be able make use of the strings even when the JSON loading function is exited so thats why I try to copy the string into the array of string literals. Also not touch other string indexes that I didn't have to replace with new strings. But they all crash or give empty strings.
I try to stay away from std::string and instead use char*'s because std::string is slow with huge initialized list
int size = strlen(mapName.ToString().c_str());
char* str = new char[size + 1];
str[size] = '\0';
//std::copy(mapName.ToString().c_str(), mapName.ToString().c_str() + size, MapIds[std::stoi(mapId.ToString().c_str())]); //fails
//strcpy(MapIds[std::stoi(mapId.ToString().c_str())], mapName.ToString().c_str()); //fails
//MapIds[std::stoi(mapId.ToString().c_str())] = mapName.ToString().c_str(); //fails
//sprintf(MapIds[std::stoi(mapId.ToString().c_str())], "%s", mapName.ToString().c_str()); //fails
MapIds[0] = "gfggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg"; //this good
printf("map0 = %s, map1 = %s, map2 = %s\n", MapIds[0], MapIds[1], MapIds[2]);