Thread: Txt file and data storage

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You can't and you don't need to "create names" on runtime. Instead (and that is every time you wish for a way to create names with numbers appended to them) you use an array (or vector).

    In my example I showed some typedefs. The second one is for a vector of vectors of Points. The point of the typedefs is that they can shorted otherwise very long typenames. Instead you could also type:

    Code:
    std::vector<Point> one_path;
    std::vector<std::vector<Point> > lots_of_paths;
    You are right about how you would access the coordinates in a single path. In a collection of paths the syntax would be similar to two-dimensional arrays:
    Code:
    unsigned path_no = 10;
    unsigned point_no = 12;
    
    lots_of_paths[path_no][point_no].x = 42;

    Or create a reference to a single path if we need to do lots of things with it:
    Code:
    std::vector<Point>& interesting_path = lots_of_paths[42];
    interesting_path[10].y = 3;
    
    //because interesting_path is a reference the last line affects
    //lots_of_paths[42][10].y
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  2. #2
    Registered User
    Join Date
    Jun 2008
    Posts
    33
    Thank you for everything anon. You've been a great help.

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    33
    It's me again. lots_of_paths[0] stands for my first path, lots_of_paths[1] for second and so on (if i'm not mistaking). How can i find out the number of complete paths in lots_of_paths. Is there a way to find out number of elements in vector? And what function should i use for reading file and storing numbers? get(ch), or what? I need something that ignores spaces.
    Last edited by radnik; 06-16-2008 at 03:16 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM