Mail Archives: djgpp/1999/10/13/15:52:31
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<vector<int> > a;
<br>...
<br>const int ROWS=5; const int COLS=7;
<br>...
<br>a.resize(ROWS);
<br>for (int r=0; r < ROWS; r++) a[r].resize(COLS);
<p> 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>
<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<int> a(10); allocates a one-d vector of
<br>>ten elements. I want to do something like
<br>>
<br>>vector< vector<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<vector<int> > a(10);
<br>for_each(a.begin(), a.end(),
<br> bind2nd(mem_fun1(&vector::resize), 10));
<p>Make sure to #include <algorithm> and <functional>
<br>as well as <vector>. 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 -