473,387 Members | 1,669 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,387 software developers and data experts.

4D array

Hey. I was attempting a four-dimensional array and I couldn't get it to
work. The code below gave me 23 errors:

// BEGIN CODE
int main() {

int nArray[2][2][2][2] = {

{ { {1,2} , {3,4} } , { {5,6} , {7,8} } }

{ { {9,10} , {11,12} } , { {13,14} , {15,16} } }

};

cout << "nArray[0][0][0][0]: " << nArray[0][0][0][0] << endl;

cout << "nArray[1][0][1][0]: " << nArray[1][0][1][0] << endl;

cout << "nArray[1][1][0][1]: " << nArray[1][1][0][1] << endl;

return 0;

}

// END CODE

I'm fairly certain that the code should work; it was an expansion on a
working 3D array I had just finished, and I've gone over it several times.
I'm pretty sure I'll never need a 4D array, but I'd like to know why this
one doesn't work.
Jul 22 '05 #1
5 3231

int nArray[2][2][2][2] = {
{ { {1,2} , {3,4} } , { {5,6} , {7,8} } }, //<-- forgot a comma-sign to
separate the first half and the second half
{ { {9,10} , {11,12} } , { {13,14} , {15,16} } }
//JT
Jul 22 '05 #2
Stephen Tyndall wrote:
Hey. I was attempting a four-dimensional array and I couldn't get it to
work. The code below gave me 23 errors:

// BEGIN CODE
int main() {

int nArray[2][2][2][2] = {

{ { {1,2} , {3,4} } , { {5,6} , {7,8} } } You are missing a ',' at the end of the above line.

{ { {9,10} , {11,12} } , { {13,14} , {15,16} } }

};

cout << "nArray[0][0][0][0]: " << nArray[0][0][0][0] << endl;

cout << "nArray[1][0][1][0]: " << nArray[1][0][1][0] << endl;

cout << "nArray[1][1][0][1]: " << nArray[1][1][0][1] << endl;

return 0;

}


Here is my code that works:
TH009MA@th009ma-shl2-01 /cygdrive/d/temp
$ cat junk.cpp
#include <iostream>
using namespace std;

int main() {

int nArray[2][2][2][2] = {

{ { {1, 2} , { 3, 4} } , { { 5, 6} , { 7, 8} } },

{ { {9,10} , {11,12} } , { {13,14} , {15,16} } }

};

cout << "nArray[0][0][0][0]: " << nArray[0][0][0][0] << endl;

cout << "nArray[1][0][1][0]: " << nArray[1][0][1][0] << endl;

cout << "nArray[1][1][0][1]: " << nArray[1][1][0][1] << endl;

return 0;

}
TH009MA@th009ma-shl2-01 /cygdrive/d/temp
$ g++ -o junk junk.cpp

TH009MA@th009ma-shl2-01 /cygdrive/d/temp
$ ./junk
nArray[0][0][0][0]: 1
nArray[1][0][1][0]: 11
nArray[1][1][0][1]: 14

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #3
Hey, thanks guys. Good eye.

"jota" <ab*@hotmail.com> wrote in message
news:dW******************@newsb.telia.net...

int nArray[2][2][2][2] = {
{ { {1,2} , {3,4} } , { {5,6} , {7,8} } }, //<-- forgot a comma-sign to
separate the first half and the second half
{ { {9,10} , {11,12} } , { {13,14} , {15,16} } }
//JT

Jul 22 '05 #4
Stephen Tyndall wrote:
Hey.
Hey yourself.
I was attempting a four-dimensional array and I couldn't get it to
work. The code below gave me 23 errors:
What 23 errors?

// BEGIN CODE
int main() {

int nArray[2][2][2][2] = {

{ { {1,2} , {3,4} } , { {5,6} , {7,8} } }

{ { {9,10} , {11,12} } , { {13,14} , {15,16} } }

};

cout << "nArray[0][0][0][0]: " << nArray[0][0][0][0] << endl;
It seems that 'cout' and 'endl' are undefined at this point. Are
you sure you didn't forget

#include <iostream>
using std::cout;
using std::endl;

at the beginning of your code?

cout << "nArray[1][0][1][0]: " << nArray[1][0][1][0] << endl;

cout << "nArray[1][1][0][1]: " << nArray[1][1][0][1] << endl;

return 0;

}

// END CODE

I'm fairly certain that the code should work; it was an expansion on a
working 3D array I had just finished, and I've gone over it several times.
I'm pretty sure I'll never need a 4D array, but I'd like to know why this
one doesn't work.


What particularly "doesn't work"?

V
Jul 22 '05 #5
The only thing wrong was a comma at the end of the second line of array
code. I only put the code for main() in the original message. At the end
of the message, I wrote that the three-dimensional array I programmed before
worked perfectly fine. That would seem to imply that the problem is with
the array.

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:xu****************@ord-read.news.verio.net...
Stephen Tyndall wrote:
Hey.


Hey yourself.
> I was attempting a four-dimensional array and I couldn't get it to
work. The code below gave me 23 errors:


What 23 errors?

// BEGIN CODE
int main() {

int nArray[2][2][2][2] = {

{ { {1,2} , {3,4} } , { {5,6} , {7,8} } }

{ { {9,10} , {11,12} } , { {13,14} , {15,16} } }

};

cout << "nArray[0][0][0][0]: " << nArray[0][0][0][0] << endl;


It seems that 'cout' and 'endl' are undefined at this point. Are
you sure you didn't forget

#include <iostream>
using std::cout;
using std::endl;

at the beginning of your code?

cout << "nArray[1][0][1][0]: " << nArray[1][0][1][0] << endl;

cout << "nArray[1][1][0][1]: " << nArray[1][1][0][1] << endl;

return 0;

}

// END CODE

I'm fairly certain that the code should work; it was an expansion on a
working 3D array I had just finished, and I've gone over it several times. I'm pretty sure I'll never need a 4D array, but I'd like to know why this one doesn't work.


What particularly "doesn't work"?

V

Jul 22 '05 #6

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

Similar topics

2
by: Brian | last post by:
I'm diddlying with a script, and found some behavior I don't understand. Take this snippet: for ($i = 0; $i <= count($m); $i++) { array_shift($m); reset($m); }
2
by: Stormkid | last post by:
Hi Group I'm trying to figure out a way that I can take two (two dimensional) arrays and avShed and shed, and subtract the matching elements in shed from avShed I've pasted the arrays blow from a...
15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
8
by: vcardillo | last post by:
Hello all, Okay, I am having some troubles. What I am doing here is dealing with an employee hierarchy that is stored in an array. It looks like this: $employees = array( "user_id" => array(...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
8
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.