Hi,

I want to create a sequence of vector<double> each with a name + a number that goes from say 0 to 9.
For example, how do I make a loop that creates10 vector<double> that goes by the name : vector_0, vector_1, ..., vector_9 ?

Thanks.

you can't do that. But what you can do is have a vector of vectors, just like a 2d array of doubles

vector<double> columns;
vector<columns> rows;

Now each row is like your vector_0, vector_1, etc.

Or perhaps use vectors of pair of string and double.

#include<utility>
#include<vector>
#include<string>
int main()
{
std::vector<std::pair<std::string,double> > Foo;
Foo.push_back( pair("Sally",1021) );
Foo.push_back( pair("John",3.14021) );
std::cout<<"Name:" <<Foo[1].first<<"  GPA:"<<Foo[1].second;
}
commented: Please consider indenting your code and use of whitespace kiddo. -4
commented: Negate more of 'iamthepiss' pendantry. +33

>USE AN ARRAY!
One of the baddest advice that can be given to a beginner.
Don't you know that arrays are evil?
>efficiency before sophistication.
Err. The better way to saying is : 'Clarity before efficiency".
As Donald Knuth puts up very beautifully:"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."

Besides, you should ``show" the user the ``path" rather than showing him just the direction-posts.

commented: Excellent :) +36
commented: Excellent! +7
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.