Thread: String to object name.

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    6

    String to object name.

    Say I have a lot of objects of the same class. I also have a string, which I know is the same as the name of one of the objects. Also, each object has a string variable which is the same as its name. How can I call on the object relevant to the string in my code?

    If I have done a poor job in explaining myself, tell me.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    I would put all the objects in a map. This way you can do something like:

    Code:
    myclass* c = mymap["object_name"];
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    6
    So an array of objects?

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, a map. Check out std::map.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to CPP -> convert Object to String
    By smash84 in forum C++ Programming
    Replies: 9
    Last Post: 06-08-2006, 02:58 PM
  2. string object problem
    By ssharish2005 in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 08:21 AM
  3. Null character and string object
    By Jeb. in forum C++ Programming
    Replies: 3
    Last Post: 11-01-2003, 11:12 PM
  4. char* to string object
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 04-01-2002, 03:08 PM
  5. string object to null-terminating string conversion
    By sayz0 in forum C++ Programming
    Replies: 2
    Last Post: 11-05-2001, 12:15 PM