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. typedef struct (?)

typedef struct (?)

Scheduled Pinned Locked Moved C / C++ / MFC
c++questiondatabasedata-structures
4 Posts 3 Posters 0 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.
  • F Offline
    F Offline
    Frank Deo
    wrote on last edited by
    #1

    Hello, I have a function that returns several strings. This function is run over and over again many times. I would like to store all the returned strings in an array. I'm assuming that I have to use a struct. But, how do I get the values inside by index after its created. In VB (yea, i know.) :) It would be something like this: Private Type StrData String1 as string String2 as String End Type Then to access the array it would be something like this: rtn = StrData.String1(0) So, how do I convert this to C++ and MFC? Thanks! Frank :)

    M S 2 Replies Last reply
    0
    • F Frank Deo

      Hello, I have a function that returns several strings. This function is run over and over again many times. I would like to store all the returned strings in an array. I'm assuming that I have to use a struct. But, how do I get the values inside by index after its created. In VB (yea, i know.) :) It would be something like this: Private Type StrData String1 as string String2 as String End Type Then to access the array it would be something like this: rtn = StrData.String1(0) So, how do I convert this to C++ and MFC? Thanks! Frank :)

      M Offline
      M Offline
      Mike Dunn
      wrote on last edited by
      #2

      I don't understand what rtn = StrData.String1(0) means exactly. What is the (0) there for? "String1" isn't an array. Anyway, to make a typedef'd struct:

      typedef struct
      {
      CString String1, String2;
      } StrData;

      To make an array of those, you can use a linked list (since it sounds like you don't know exactly how many structs you'll have). Use std::list<StrData> in STL, or CList<StrData, StrData&> in MFC.

      F 1 Reply Last reply
      0
      • M Mike Dunn

        I don't understand what rtn = StrData.String1(0) means exactly. What is the (0) there for? "String1" isn't an array. Anyway, to make a typedef'd struct:

        typedef struct
        {
        CString String1, String2;
        } StrData;

        To make an array of those, you can use a linked list (since it sounds like you don't know exactly how many structs you'll have). Use std::list<StrData> in STL, or CList<StrData, StrData&> in MFC.

        F Offline
        F Offline
        Frank Deo
        wrote on last edited by
        #3

        Thanks Mike. In VB, rtn = StrData.String1(0) the (0) is the index of the n'th (where n is just a number) String1 object contained in the data type StrData. (I think) :) I'm afraid I'm new to using "Linked Lists". Could you expand a bit on the usage in MFC? What do I do with the code CList. Thanks again, Frank

        1 Reply Last reply
        0
        • F Frank Deo

          Hello, I have a function that returns several strings. This function is run over and over again many times. I would like to store all the returned strings in an array. I'm assuming that I have to use a struct. But, how do I get the values inside by index after its created. In VB (yea, i know.) :) It would be something like this: Private Type StrData String1 as string String2 as String End Type Then to access the array it would be something like this: rtn = StrData.String1(0) So, how do I convert this to C++ and MFC? Thanks! Frank :)

          S Offline
          S Offline
          Sam Hobbs
          wrote on last edited by
          #4

          See: http://home.socal.rr.com/samhobbs/VC/Collections.html CStringList is really easy to use but the MFC documentation is not. I hope the example in the above page is easy though.

          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