Array problem

This is a discussion on Array problem within the C++ Programming forums, part of the General Programming Boards category; Hi folks, I'm trying to write an optimiser utility that takes a .b3d file and merges the meshblocks together for ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    2

    Array problem

    Hi folks, I'm trying to write an optimiser utility that takes a .b3d file and merges the meshblocks together for instance

    [meshbuilder]
    vertex 1.0,2.0,3.0
    face 0,1,2,3
    [meshbuilder]
    vertex 4.0,5.0,6.0
    face 0,1,2,3

    would now read

    [meshbuilder]
    vertex 1.0,2.0,3.0
    vertex 4.0,5.0,6.0
    face 0,1,2,3
    face 4,5,6,7

    the way i'm trying to do it is to save the vertex and face element separately, so what i wanted to do was to save the address of each line in a different section of an array, so all the 'face' lines get saved in one part of the array and the 'vertex' ones in another. then what I want to do is output the 1st element of the array then point to the next element, meaning the face statements should come out one after the other instead of being separated. the problem is that trying to make an array containing the addresses of each line doesn't seem to work for me. is there an easy way to make an array containing addresses, rather than integers and strings etc?

    I'm not trying to sort the data into the largest number of alphabetic etc (i wish i was)
    i'm tearing my hair out!

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,533
    Maybe use two vectors of strings?

    std::vector< std::string > vertices;
    std::vector< std::string > faces;

    When you read each line, decide which vector you want to push_back on, based on the first word in the line (lookup the appropriate std::string method to do this)

    When you're done, just output all the vertices, then all the faces.

    Should be about 20 lines tops.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    2
    I haven't come across lists yet, but i see what you're getting at and how it can be simpler than the way i was trying to do it. just so I can confirm my understanding:

    1) make two lists, one containing vertexes and faces.
    2) compare each line coming in and use the push_back function to put it to the end of each appropriate list?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,533
    yes.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  2. Replies: 6
    Last Post: 02-15-2005, 10:20 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Need desperate help with two dimensional array problem
    By webvigator2k in forum C++ Programming
    Replies: 4
    Last Post: 05-10-2003, 02:28 PM
  5. From stream/file to a string array problem
    By dradsws in forum C Programming
    Replies: 2
    Last Post: 10-01-2001, 06:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21