473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

please help me...

Pat
Hi,
I want to use "new" to build an array test[1000][1000]. Can you tell me how
to do?

Thank.

Pat
Jul 22 '05 #1
7 1168
Pat
I don't want to use "int test[1000][1000]".

Thanks.
"Pat" <Pa*@Pat.com> ¦b¶l¥ó news:40**********@rain.i-cable.com ¤¤¼¶¼g...
Hi,
I want to use "new" to build an array test[1000][1000]. Can you tell me how to do?

Thank.

Pat

Jul 22 '05 #2
Pat wrote:
I don't want to use "int test[1000][1000]".

Thanks.
"Pat" <Pa*@Pat.com> ¦b¶l¥ó news:40**********@rain.i-cable.com
¤¤¼¶¼g...
Hi,
I want to use "new" to build an array test[1000][1000]. Can you tell
me how to do?

Thank.

Pat


Try a jagged vector of vectors:

(not compiled)

vector<vector<int> > arr;
arr.resize(1000);
for(int i =0;i<1000;++i)
arr[i].resize(1000);

Then simply:
arr[x][y] = 1234;

- Pete
Jul 22 '05 #3
Pat writes:
I want to use "new" to build an array test[1000][1000]. Can you tell me how to do?


This works.

<add boilerplate>

void foo(int b[][4])
{
cout << b[2][3] << endl;
}

void test()
{
int(*a)[4] = new int[3][4];
a[2][3] = 1024;
foo(a);
}
Jul 22 '05 #4
"Pat" <Pa*@Pat.com> wrote in message news:40**********@rain.i-cable.com...
Hi,
I want to use "new" to build an array test[1000][1000]. Can you tell me how to do?


http://www.parashift.com/c++-faq-lit...html#faq-16.15

Always check the FAQ before posting a question.

-Mike
Jul 22 '05 #5
TJB

"Pat" <Pa*@Pat.com> wrote in message news:40**********@rain.i-cable.com...
Hi,
I want to use "new" to build an array test[1000][1000]. Can you tell me how to do?

Thank.

Pat

Hi,

You have to create an array of arrays like this:

int i,**test;

test = new int*[1000];
for (i = 0; i < 1000; i++)
test[i] = new int[1000];

You could also start with an array of pointers, int* test[1000], and
initialize the elements in it.
Jul 22 '05 #6
* "TJB" <ce*******@telia.com> schriebt:

"Pat" <Pa*@Pat.com> wrote in message news:40**********@rain.i-cable.com...

I want to use "new" to build an array test[1000][1000]. Can you tell me
how to do?


You have to create an array of arrays like this:

int i,**test;

test = new int*[1000];
for (i = 0; i < 1000; i++)
test[i] = new int[1000];

You could also start with an array of pointers, int* test[1000], and
initialize the elements in it.


Well no, e doesn't "have to".

Except if e _really_ doesn't want a two-dimensional array.

See the answer from osmium earlier in the thread about how to allocate
a two-dimensional array using new,

int (*p)[1000] = new int[1000][1000];

The general question is also a FAQ, see
<url: http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.15>,
"How do I allocate a multidimensional array using new?"

Unfortunately, in spite of the heading the FAQ does not show how to allocate
a multidimensional array using new (!), only jagged arrays like yours. But
it does go on to show a few generally much better ways.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #7

"osmium" <r1********@comcast.net> skrev i meddelandet
news:c2*************@ID-179017.news.uni-berlin.de...
Pat writes:
int(*a)[4] = new int[3][4];


Maybe you should point out that this only works if the number of items in
the second dimension (=4) is known at compile time, which limits the
usefullness of this method.
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Numberwhun | last post by:
Hello everyone! I am trying to learn java and have run into kind of a snag. Here is the code that I have so far: ------ <begin_code> ---------- import javax.swing.*; import...
1
by: HolaGoogle | last post by:
Hi all, Please help me with the following..it's realy urgent and i tried everything i could and i can't get it work properly!! Thanks in advance. Here's what i'm trying to accomplish: in my...
0
by: s_erez | last post by:
Hi, This is a realy tricky one. I have an ASP.NET application where some pages are reading data from a DB and presenting reports. In order for the user to wait while the page is reading data from...
2
by: rked | last post by:
I get nameSPAN1 is undefined when I place cursor in comments box.. <%@ LANGUAGE="VBScript" %> <% DIM ipAddress ipAddress=Request.Servervariables("REMOTE_HOST") %> <html> <head> <meta...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
4
by: pshindle | last post by:
DB2 Team - I just downloaded and unzipped the new Fixpack 9 for DB2 ESE V8 for Windows (FP9_WR21350_ESE.exe). I then burned the unzipped Fixpack files to a CD. I proceded to install this...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
1
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and...
4
by: fatboySudsy | last post by:
Hi, I have constructed a client program that has given me some error codes that i just cannot see. I was wondering if a different set of eyes with much more experience than me could help me out. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.