www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/13/15:52:31

Message-ID: <38048A27.5BF1BA2A@arcticmail.com>
From: N J Chackowsky <nick AT arcticmail DOT com>
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>
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

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
I did finally get around the problem another way:
<p>vector&lt;vector&lt;int> > a;
<br>...
<br>const int ROWS=5; const int COLS=7;
<br>...
<br>a.resize(ROWS);
<br>for (int r=0; r &lt; ROWS; r++) a[r].resize(COLS);
<p>&nbsp;&nbsp;&nbsp;&nbsp; Isn't for_each just a "disguized" loop?
<p>Thanks for all the help, everyone. Sorry, I'm not ready to go to Ada
just yet :)
<p>Nick.
<br>&nbsp;
<p>Kenn Hamm wrote:
<blockquote TYPE=CITE>>Yes, but not quite the problem I'm trying to
<br>>solve. I understand about checked or unchecked
<br>>indexing, but how do I pre-allocate for a
<br>>particular size of matrix?
<br>>
<br>>vector&lt;int> a(10); allocates a one-d vector of
<br>>ten elements. I want to do something like
<br>>
<br>>vector&lt; vector&lt;int>(10) > a(10); to allocate a
<br>>matrix with ten rows and ten columns, instead of
<br>>doing
<br>>
<br>>int a[10][10];
<br>>
<br>>I'm not sure this is possible with the STL.
<br>>Perhaps I need to write a two-d matrix class?
<br>>
<p>The way I would do this is
<p>vector&lt;vector&lt;int> > a(10);
<br>for_each(a.begin(), a.end(),
<br>&nbsp; bind2nd(mem_fun1(&amp;vector::resize), 10));
<p>Make sure to #include &lt;algorithm> and &lt;functional>
<br>as well as &lt;vector>.&nbsp; Not the most elegant solution
<br>in the world, but still better than having to write
<br>a for loop every time you want to do it, and of
<br>course you could write your own function to do what
<br>the second line of code does for you.
<p>Hope it helps.
<p>Kenn
<p>=====
<p>__________________________________________________
<br>Do You Yahoo!?
<br>Bid and sell for free at <a href="http://auctions.yahoo.com">http://auctions.yahoo.com</a></blockquote>
</html>

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019