Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Strings to Variable Names

Strings to Variable Names

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structurescollaborationtutorial
4 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    James A Beggs
    wrote on last edited by
    #1

    I am a professional, but unfortunately junior, developer, and I'm looking to do something that I thought I knew how to do. Now, I cannot recall how to do it, and I'm feeling... well, terribly ignorant. What is going on is I want to create an array of arrays - in specific, I'm making a pointer of pointers, actually. I want each of the pointers in the "array" to point at an object of the same type. I wanted to set up a for-loop to assign these. In other words, I have something like: TCSpinEdit ** SpinnerArray; SpinnerArray = new TCSpinEdit *[58]; for (int iCtr = 0; iCtr < 58; iCtr++) the name of each of these objects starts out with CSpin followed by a number, from 1 to 58; so I need to point to CSpin1, then CSpin2, etc. Therefore, I need to generate a string, or whathave you, to designate each CSpin variable to each of the pointes in the array. And I realized I was unsure how to go about this. I started originally by using the string class; assign it as: string = "Cspin" + iCtr; But I realized I wasn't sure how to use the string to refer to a variable NAME. Any suggestions? Thanks! James A Beggs Microsoft MSN Mobile Component Test Team

    A C J 3 Replies Last reply
    0
    • J James A Beggs

      I am a professional, but unfortunately junior, developer, and I'm looking to do something that I thought I knew how to do. Now, I cannot recall how to do it, and I'm feeling... well, terribly ignorant. What is going on is I want to create an array of arrays - in specific, I'm making a pointer of pointers, actually. I want each of the pointers in the "array" to point at an object of the same type. I wanted to set up a for-loop to assign these. In other words, I have something like: TCSpinEdit ** SpinnerArray; SpinnerArray = new TCSpinEdit *[58]; for (int iCtr = 0; iCtr < 58; iCtr++) the name of each of these objects starts out with CSpin followed by a number, from 1 to 58; so I need to point to CSpin1, then CSpin2, etc. Therefore, I need to generate a string, or whathave you, to designate each CSpin variable to each of the pointes in the array. And I realized I was unsure how to go about this. I started originally by using the string class; assign it as: string = "Cspin" + iCtr; But I realized I wasn't sure how to use the string to refer to a variable NAME. Any suggestions? Thanks! James A Beggs Microsoft MSN Mobile Component Test Team

      A Offline
      A Offline
      Abin
      wrote on last edited by
      #2

      I'm not sure if I understood you completely but in C++ there's no such association between a varaible name and a string, a variable name is merely a symbol by which you tell the compiler that you are about to request a block of memory, whereas a string is an array of characters. You cannot "convert" them into each other because they are totally different concepts.

      1 Reply Last reply
      0
      • J James A Beggs

        I am a professional, but unfortunately junior, developer, and I'm looking to do something that I thought I knew how to do. Now, I cannot recall how to do it, and I'm feeling... well, terribly ignorant. What is going on is I want to create an array of arrays - in specific, I'm making a pointer of pointers, actually. I want each of the pointers in the "array" to point at an object of the same type. I wanted to set up a for-loop to assign these. In other words, I have something like: TCSpinEdit ** SpinnerArray; SpinnerArray = new TCSpinEdit *[58]; for (int iCtr = 0; iCtr < 58; iCtr++) the name of each of these objects starts out with CSpin followed by a number, from 1 to 58; so I need to point to CSpin1, then CSpin2, etc. Therefore, I need to generate a string, or whathave you, to designate each CSpin variable to each of the pointes in the array. And I realized I was unsure how to go about this. I started originally by using the string class; assign it as: string = "Cspin" + iCtr; But I realized I wasn't sure how to use the string to refer to a variable NAME. Any suggestions? Thanks! James A Beggs Microsoft MSN Mobile Component Test Team

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        Hum, I think I don't really understand you but why do you make so complicated ??? Why don't you just acces the array as normally like that: TCSpinEdit* Temp; for (int iCtr=0;iCtr<58;iCtr++) Temp = SpinnerArray[iCtr];

        1 Reply Last reply
        0
        • J James A Beggs

          I am a professional, but unfortunately junior, developer, and I'm looking to do something that I thought I knew how to do. Now, I cannot recall how to do it, and I'm feeling... well, terribly ignorant. What is going on is I want to create an array of arrays - in specific, I'm making a pointer of pointers, actually. I want each of the pointers in the "array" to point at an object of the same type. I wanted to set up a for-loop to assign these. In other words, I have something like: TCSpinEdit ** SpinnerArray; SpinnerArray = new TCSpinEdit *[58]; for (int iCtr = 0; iCtr < 58; iCtr++) the name of each of these objects starts out with CSpin followed by a number, from 1 to 58; so I need to point to CSpin1, then CSpin2, etc. Therefore, I need to generate a string, or whathave you, to designate each CSpin variable to each of the pointes in the array. And I realized I was unsure how to go about this. I started originally by using the string class; assign it as: string = "Cspin" + iCtr; But I realized I wasn't sure how to use the string to refer to a variable NAME. Any suggestions? Thanks! James A Beggs Microsoft MSN Mobile Component Test Team

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #4

          You seem to be confused about what you really want - I try to give you an explanation, and maybe you can then decide if this was what you intended.: James A Beggs wrote: TCSpinEdit ** SpinnerArray; SpinnerArray = new TCSpinEdit *[58]; for (int iCtr = 0; iCtr < 58; iCtr++) So you have a pointer to an array of 58 TCSpinEdit*s. In your for-loop you need to initialize each of the TCSpinEdit* 0 to 57 with a pointer to a TCSpinEdit:

          for (int iCtr = 0; iCtr < 58; iCtr++)
          {
          SpinnerArray[iCtr]= new TCSpinEdit( parameter );
          {

          Your TCSpinners are now accessed as SpinnerArray[i], where i=0..57. If you need - for whatever reason - a association between your TCSpinners and some other data, e.g. a string, you might use a std::map < string, int > to store pairs of strings and indices into your SpinnerArray.


          My opinions may have changed, but not the fact that I am right.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups