0

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.

4
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by siddhant3s
0

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.

0

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;
}
Votes + Comments
Negate more of 'iamthepiss' pendantry.
Please consider indenting your code and use of whitespace kiddo.
2

>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.

Votes + Comments
Excellent!
Excellent :)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.