Thread: List, selected text to string?

  1. #1
    Registered User
    Join Date
    Sep 2007

    List, selected text to string?

    I wonder how I set “cout<< list.getText(list.selectedItemIndex);" to get the string with that name instead of only paste the name that is selected.

    Let´s say I select “FIRE" in the list, and I have a string with the name FIRE.
    How do I paste the string FIRE instead of the selected text "FIRE"?

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    You don't.

    Variable names are generally used only for the programmer to specify which memory address he's dealing with, not for programs to figure things out about itself. When that does occur, it's known as "Reflection" in OOP languages that support it. C++ supports it I think up to a very limited point with certain run time libraries, but not natively afaik (or at least up to the level of detail that you would like). Languages like Java supports this type of thing, as well as more modern OOP languages.

    There are ways of working around this, but it depends upon how you want to go about it. For example, you could have a struct or class that contains two strings, where one would be your regular data, and the other would be the name of the entry, like "fire". That's the idea behind how Reflection is done in other languages I believe.

    There are ways of getting names of variables, but that's generally with shared memory in the form of DLLs on Windows and .so files on *nix, and it doesn't sound like it's what you want, although a DLL solution could be done with this type of problem.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    What you want is a mapping of strings to other things. You can do that with a std::map or any other associative container.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  3. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  4. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 10:16 AM