Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

c++ - Initializing a vector of vectors having a fixed size with boost assign

Having a vector of vector with a fixed size,

vector<vector<int> > v(10);

I would like to initialize it so that it has in all elements a one dimensional vector with initialized value (for example 1).

I have used Boost Assign as follows

v = repeat(10,list_of(list_of(1)));

and I've got a compilation error

error: no matching function for call to ‘repeat(boost::assign_detail::generic_list<int>)’

Could you please tell me how to do that. Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This doesn't use boost::assign but does what you need:

vector<vector<int>> v(10, vector<int>(10,1));

This creates a vector containing 10 vectors of int, each containing 10 ints.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...