Message-ID: <38048A27.5BF1BA2A@arcticmail.com> From: N J Chackowsky X-Mailer: Mozilla 4.5 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: vector of vectors References: <19991008135627 DOT 27300 DOT rocketmail AT web117 DOT yahoomail DOT com> Content-Type: multipart/mixed; boundary="------------10CBB251EEA29ACCB573CD24" Lines: 81 Date: Wed, 13 Oct 1999 13:32:51 GMT NNTP-Posting-Host: 206.45.76.85 X-Trace: typhoon.mbnet.mb.ca 939821571 206.45.76.85 (Wed, 13 Oct 1999 08:32:51 CDT) NNTP-Posting-Date: Wed, 13 Oct 1999 08:32:51 CDT Organization: MBnet Networking Inc. To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com This is a multi-part message in MIME format. --------------10CBB251EEA29ACCB573CD24 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit I did finally get around the problem another way:

vector<vector<int> > a;
...
const int ROWS=5; const int COLS=7;
...
a.resize(ROWS);
for (int r=0; r < ROWS; r++) a[r].resize(COLS);

     Isn't for_each just a "disguized" loop?

Thanks for all the help, everyone. Sorry, I'm not ready to go to Ada just yet :)

Nick.
 

Kenn Hamm wrote:

>Yes, but not quite the problem I'm trying to
>solve. I understand about checked or unchecked
>indexing, but how do I pre-allocate for a
>particular size of matrix?
>
>vector<int> a(10); allocates a one-d vector of
>ten elements. I want to do something like
>
>vector< vector<int>(10) > a(10); to allocate a
>matrix with ten rows and ten columns, instead of
>doing
>
>int a[10][10];
>
>I'm not sure this is possible with the STL.
>Perhaps I need to write a two-d matrix class?
>

The way I would do this is

vector<vector<int> > a(10);
for_each(a.begin(), a.end(),
  bind2nd(mem_fun1(&vector::resize), 10));

Make sure to #include <algorithm> and <functional>
as well as <vector>.  Not the most elegant solution
in the world, but still better than having to write
a for loop every time you want to do it, and of
course you could write your own function to do what
the second line of code does for you.

Hope it helps.

Kenn

=====

__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

--------------10CBB251EEA29ACCB573CD24 Content-Type: text/x-vcard; charset=us-ascii; name="nick.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for N J Chackowsky Content-Disposition: attachment; filename="nick.vcf" begin:vcard n:Chackowsky;Nick tel;cell:204 729 6011 tel;fax:204 729 0365 tel;home:204 728 8184 tel;work:204 729 0363 x-mozilla-html:TRUE url:http://www.brandonsd.mb.ca/massey org:Vincent Massey High School;Business Education / Technology adr:;;715 McDiarmid Drive;Brandon;Manitoba;R7B 2H7;Canada version:2.1 email;internet:nick AT arcticmail DOT com title:Teacher fn:Nick J Chackowsky end:vcard --------------10CBB251EEA29ACCB573CD24--