Assigning the value of one string to the name of an int

Let's say I have a string:

string id = "blah";

I want to make a new integer with a name that is the value of "id":

int [id]
("[id]" is just a marker for what I mean)

Is there any way to do this kind of thing?
You can't, the names are just for you. You could emulate this however by doing something like std::map<std::string, int> or something where each string maps to an int variable.
What I want to actually do is read data off an xml file. The attributes for the element I want to get from are put into strings during a For Each loop:

1
2
3
4
5
6
for(TiXmlElement* image = root->FirstChildElement(); image;
  image = image->NextSiblingElement()) {
    string id = image->Attribute("id");
         
    SDL_Surface* blah = IMG_Load( image->Attribute("path") );
}


I'm using SDL, sorry for not specifying, and for lying about the int thing. It was for simplicity. It was one of the solutions I thought of. Anyway, I want to create an SDL_Surface for each time TinyXml finds an "image" element in the xml file. The attribute "id" is pretty much just a name for the image, which I'd like to reference to later, in other files. Is there any other way I could do this where the SDL_Surface would be different and recognizable for each separate "image" element?
Well, you could have each image have a "name" element and shove them all into one big array, then you could search for them. I think a map would still be a better choice though, if you don't need to construct them.

std::map<std::string, SDL_Surface>

Or if you are using pointers like it seems you are, a boost::ptr_map might be a better choice:

boost::ptr_map<std::string, SDL_Surface> //this works differently than std::map<std::string, SFL_Surface>, check documentation

Doesn't boost::ptr_map work with newed pointers? If so, then it won't work, because SDL_Surface structs aren't newed.
An std::map<std::string,SDL_Surface *> would probably be best.
Ah, that's true. std::map would be the best here probably then.
*begins googling stuff you're talking about*
Topic archived. No new replies allowed.