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. resizing an array to the size of another array

resizing an array to the size of another array

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
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.
  • J Offline
    J Offline
    johnstonsk
    wrote on last edited by
    #1

    I need to copy an array, but I don't know the size until after the program has parsed a file. I created a pointer to the new array like this: double *data_ptr = new double[]; I then have a counter that counts as the file is parsed. I call this counter int num_signals; Once the file is parsed I nee dto resize the array with the size of num_signals. double *data_ptr = new double[num_signals]; How can I do this? thanks, sj:)

    J D 2 Replies Last reply
    0
    • J johnstonsk

      I need to copy an array, but I don't know the size until after the program has parsed a file. I created a pointer to the new array like this: double *data_ptr = new double[]; I then have a counter that counts as the file is parsed. I call this counter int num_signals; Once the file is parsed I nee dto resize the array with the size of num_signals. double *data_ptr = new double[num_signals]; How can I do this? thanks, sj:)

      J Offline
      J Offline
      John M Drescher
      wrote on last edited by
      #2

      Why not use an stl class like vector? vector will handle all the details of this for you. John

      1 Reply Last reply
      0
      • J johnstonsk

        I need to copy an array, but I don't know the size until after the program has parsed a file. I created a pointer to the new array like this: double *data_ptr = new double[]; I then have a counter that counts as the file is parsed. I call this counter int num_signals; Once the file is parsed I nee dto resize the array with the size of num_signals. double *data_ptr = new double[num_signals]; How can I do this? thanks, sj:)

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Unless you are using data_ptr during the parsing of the file, don't initialize it until afterwards.

        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