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. dynamic structure array

dynamic structure array

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestion
3 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.
  • A Offline
    A Offline
    Archer282
    wrote on last edited by
    #1

    k, say i have a structure like struct MYSTRUCT { char somestring[64]; int number; int number2; }; now i would like to be able to write an array of this structure to a file and then it read it again, preferable with a non fixed length, would it be possible to do this?

    V B 2 Replies Last reply
    0
    • A Archer282

      k, say i have a structure like struct MYSTRUCT { char somestring[64]; int number; int number2; }; now i would like to be able to write an array of this structure to a file and then it read it again, preferable with a non fixed length, would it be possible to do this?

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      you can use CFile or FILE structures to print to file. Dynamic arrays are CArrays I think. (It's been a while :sigh:) More info on MSDN. If you don't have MFC then you can write your own CArray class which isn't that difficult. good luck. No hurries, no worries.

      1 Reply Last reply
      0
      • A Archer282

        k, say i have a structure like struct MYSTRUCT { char somestring[64]; int number; int number2; }; now i would like to be able to write an array of this structure to a file and then it read it again, preferable with a non fixed length, would it be possible to do this?

        B Offline
        B Offline
        Bob Stanneveld
        wrote on last edited by
        #3

        Hello, Archer282 wrote: would it be possible to do this? Yes! Does:

        std::ostream ostr;
        /*
        open file here
        */
        for( int i = 0; i < nYourArraySize; i++ )
        ostr << YourArray[i].somestring << YourArray[i].number << YourArray[i].number2;

        help? Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

        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