Programmatically declare vectors

This is a discussion on Programmatically declare vectors within the C++ Programming forums, part of the General Programming Boards category; I wonder if it is possible to programmatically declare vectors. For example if I will return a number from somewhere ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    59

    Programmatically declare vectors

    I wonder if it is possible to programmatically declare vectors.

    For example if I will return a number from somewhere wich could be 15.
    Then I want programmatically declare 15 different vectors.

    Code:
    int Number = 0;
    
    Number = 15; //Returned Number
    
    
    //Is it possible to programmatically here declare Num1 to Num15(15 vectors)
    //in any way ?
    std::vector<double> Num1;

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    15 different vectors, or one vector with 15 elements? The vector constructor can take a size.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,768
    Why would you want to? Do you need an array of arrays (basically)?
    Then it is possible to make a vector of vectors:
    std::vector< std::vector<double> > myvec(Number);

    But the vector itself is a dynamic array, not just a single variable.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    59
    Yes, I forgot to mention. I meen 15 different vector like this and then not elements:

    Code:
    std::vector<double> Num1;
    std::vector<double> Num2;
    std::vector<double> Num3;
    ...
    ... until:
    std::vector<double> Num15;

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Then make a vector of vectors. Something like vector< vector<double> >.

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    59
    Why I want to do that is because if my program will return in this case number 15. Then this number will stand for how many files there is in a folder ex.
    Then I want to read in each file in each vector. 1 - 15.
    Perheps this is not possible but there is an other approach to it.

    Make a vector of vector, isn&#180;t that by creating dimensions of the vector ?
    Last edited by franse; 11-10-2008 at 01:38 PM.

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,768
    Mine and tabstop's suggestion will work for this. Make a vector of vectors.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    59
    I understand.. I just have to check if this solution will be good/ possible if I need to declare about 20 000 vectors.
    Yes that is much
    Last edited by franse; 11-10-2008 at 01:46 PM.

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by franse View Post
    Why I want to do that is because if my program will return in this case number 15. Then this number will stand for how many files there is in a folder ex.
    Then I want to read in each file in each vector. 1 - 15.
    Perheps this is not possible but there is an other approach to it.

    Make a vector of vector, isnīt that by creating dimensions of the vector ?
    Why would want a vector of vectors, then? Wouldn't you want a vector of file_data_structure (whatever you're using)? Even if you are using a vector for each file, you could typedef it so that people (and you!) know what's going on.

  10. #10
    Registered User
    Join Date
    Oct 2008
    Posts
    59
    I haven&#180;t worked to much by doing vectors out of vector. Using typedef should look something like this, I think:
    Code:
    typedef vector<std::string> string1;
    typedef vector<string1> string2;
    typedef vector<string2> string3;
    
    	String3 Three;
    By doing that, I have created 3 dimensions and if I will have like 5000 of these dimension, I am not sure if that will be difficult to know which dimension was for what or perheps it is.

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If you have 5000 dimensions, you have way way way way way way way way way way bigger problems.

  12. #12
    Registered User
    Join Date
    Oct 2008
    Posts
    59
    That is what I am a bit afraid of. What problem are you thinking of, is it memory problems, that it will take up much RAM ?
    (I will fill each vector or dimension with say 50 lines &#225; 1 line = 50 characters from a file.)

  13. #13
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    5000 dimensions!!!
    I'm pretty sure you don't know what that actually means.
    I've never needed to use more than about 3 dimensions in my life.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  14. #14
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,768
    I think that perhaps you do not need to read the entire file contents into memory. Waste of memory and cpu time.
    Each vector can hold an entire file. So you will simply want ONE vector that can hold the vector who holds the file contents. Get me?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    There's a limit on the number of dimensions, but I don't know what it is. If you have 5000 dimensions that means you have seriously done something wrong with your data structure.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vectors
    By naseerhaider in forum C++ Programming
    Replies: 11
    Last Post: 05-09-2008, 08:21 AM
  2. How can i made vectors measuring program in DevC++
    By flame82 in forum C Programming
    Replies: 1
    Last Post: 05-07-2008, 02:05 PM
  3. How properly get data out of vectors of templates?
    By 6tr6tr in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 10:35 AM
  4. How to use Vector's in C++ !?!
    By IndioDoido in forum C++ Programming
    Replies: 3
    Last Post: 10-14-2007, 11:13 AM
  5. Points, vectors, matrices
    By subnet_rx in forum Game Programming
    Replies: 17
    Last Post: 01-11-2002, 01:29 PM

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