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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem in deleting a specific record in an array in C++

Problem in deleting a specific record in an array in C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++questiondata-structureshelptutorial
5 Posts 4 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.
  • G Offline
    G Offline
    grscot
    wrote on last edited by
    #1

    Hi everybody, How can I delete a specific record from an array in the Visual C++ environment? I have an array of object pointers. I want to enter a book title for example from the keyboard and then to have an option of deleting it, from the array. Is this possible? Regards, grscot

    D R C 3 Replies Last reply
    0
    • G grscot

      Hi everybody, How can I delete a specific record from an array in the Visual C++ environment? I have an array of object pointers. I want to enter a book title for example from the keyboard and then to have an option of deleting it, from the array. Is this possible? Regards, grscot

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

      First you would need to delete the block of memory that the array element is pointing to. Then you would need to delete the array element itself by moving all elements after the one to be deleted to the left. Let me see if a picture will help: ----------------- |0|1|2|3|4|5|6|7| ----------------- If you wanted to remove element #4, elements 5, 6, and 7 would be moved to the left one time, like: ----------------- |0|1|2|3|5|6|7| | ----------------- Now you have an empty spot where element #7 used to be. You can either free it up, or leave it so that when another element is added, the memory is already allocated.

      1 Reply Last reply
      0
      • G grscot

        Hi everybody, How can I delete a specific record from an array in the Visual C++ environment? I have an array of object pointers. I want to enter a book title for example from the keyboard and then to have an option of deleting it, from the array. Is this possible? Regards, grscot

        R Offline
        R Offline
        Rickard Andersson20
        wrote on last edited by
        #3

        You have to iterate through the array and check the value if it is the same as what the user entered and then assign it NULL. Rickard Andersson8 Here is my card, contact me later! UIN: 50302279 E-Mail: nikado@pc.nu Interests: C++, ADO, SQL, Winsock, 0s and 1s

        1 Reply Last reply
        0
        • G grscot

          Hi everybody, How can I delete a specific record from an array in the Visual C++ environment? I have an array of object pointers. I want to enter a book title for example from the keyboard and then to have an option of deleting it, from the array. Is this possible? Regards, grscot

          C Offline
          C Offline
          Cambalindo
          wrote on last edited by
          #4

          Or you can use the MFC CArray wich is a template, that takes care of everything. #include "Afxtempl.h" CArray arObj; arObj[n].RemoveAt(index);//it will remove the element and shift to the left there are plenty of method to do everything you need. cheers! Daniel Cespedes Daza "Santa Cruz de la Sierra Paraiso Terrenal!" daniel.cespedes@ieee.org

          C 1 Reply Last reply
          0
          • C Cambalindo

            Or you can use the MFC CArray wich is a template, that takes care of everything. #include "Afxtempl.h" CArray arObj; arObj[n].RemoveAt(index);//it will remove the element and shift to the left there are plenty of method to do everything you need. cheers! Daniel Cespedes Daza "Santa Cruz de la Sierra Paraiso Terrenal!" daniel.cespedes@ieee.org

            C Offline
            C Offline
            Cambalindo
            wrote on last edited by
            #5

            Cambalindo wrote: CArray arObj; This is the correct way of declaring the array CArray<myObj*,myObj&> arObj; Daniel Cespedes Daza "Santa Cruz de la Sierra Paraiso Terrenal!" daniel.cespedes@ieee.org

            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