C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Dynamische mehrdimensionale Arrays

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German)
View previous topic :: View next topic  
Author Message
Markus Krebl
Guest





PostPosted: Thu Apr 01, 2004 4:57 pm    Post subject: Dynamische mehrdimensionale Arrays Reply with quote



Hallo,

ich möchte gern mit new ein mehrdimensionales Array definieren, wobei
der Benutzer die Dimensionen festlegen kann.Wie mache ich das?

Grüsse, Markus

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
Back to top
Christoph Rabel
Guest





PostPosted: Thu Apr 01, 2004 5:59 pm    Post subject: Re: Dynamische mehrdimensionale Arrays Reply with quote



Markus Krebl wrote:
Quote:

ich möchte gern mit new ein mehrdimensionales Array definieren, wobei
der Benutzer die Dimensionen festlegen kann.Wie mache ich das?

Am besten ließest du die Arrays gleich bleiben und machtest es mit einem
vector von vectoren.

vector<vector Matrix;

Oder noch besser, du nähmmst boost::multi_array.


Da du das allerdings aufgrund der Aufgabenstellung nicht kannst:

Allokier ein eindimensionales Array und berechne die Position jeden
Elements selbst.

int *array = new int[nrows * ncolumns];

Zugreifen tust du dann so auf den Inhalt:

array[i * ncolumns + j] = 5;


Alternativ kannst du auch wie folgt vorgehen, aber diese Methode ist
äusserst fehleranfällig(nicht ausnahmesicher) und ich zeige es nur der
Vollständigkeit halber:

int **array = new int[nrows];
for(i = 0; i < nrows; i++)
array[i] = new int[ncolumns];

mfg

Christoph

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.