473,473 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

size function for multi-dimensional array?

Hi, is there a function that returns the dimensions of, say, a
two-dimensional array in c++?

Thanks,
N.
Jul 22 '05 #1
4 11639
Nancy Keuss writes:
Hi, is there a function that returns the dimensions of, say, a
two-dimensional array in c++?


Since C++ doesn't have two-dimensional arrays, the answer is no. In C++
one creates the *illusion* of two-dimensional arrays.
Jul 22 '05 #2

"osmium" <r1********@comcast.net> wrote in message news:bu************@ID-179017.news.uni-berlin.de...
Nancy Keuss writes:
Hi, is there a function that returns the dimensions of, say, a
two-dimensional array in c++?


Since C++ doesn't have two-dimensional arrays, the answer is no. In C++
one creates the *illusion* of two-dimensional arrays.

Correct, you have an array of arrays.

Jul 22 '05 #3

"Nancy Keuss" <mu*****@aol.com> wrote in message
news:d0**************************@posting.google.c om...
Hi, is there a function that returns the dimensions of, say, a
two-dimensional array in c++?

Thanks,
N.


If the compiler knows the first dimension then you might be able to use the
same trick as for 1D:

int a[M][N];

assert(sizeof(a)/sizeof(a[0]) == M);
assert(sizeof(a[0])/sizeof(a[0][0]) == N);


Jul 22 '05 #4
Nancy Keuss wrote:
Hi, is there a function that returns the dimensions of, say, a
two-dimensional array in c++?

Thanks,
N.


#include <cstddef>
#include <utility>

typedef std::pair< std::size_t, std::size_t > Dimension_Pair;

template< typename T, std::size_t n, std::size_t m >
Dimension_Pair get_dimensions( T (&)[ n ][ m ] )
{
return Dimension_Pair( n, m );
}

#include <iostream>

int main( )
{
char c[ 3 ][ 5 ];

Dimension_Pair dimensions = get_dimensions( c );

std::cout << dimensions.first << ", " << dimensions.second
<< '\n';
}

Jul 22 '05 #5

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

Similar topics

3
by: Mark | last post by:
hello! normally, if you are given binary data in a string (such as from a call to fread), you can call the strlen function on this string to get its size: $buffer = fread($file, 100000); if...
20
by: http://links.i6networks.com | last post by:
I need to display pictures, but only as large as AxB. If it is smaller than AxB, then I will display it in the original size, if it is larger than AxB, I will resize it. However, if the size is...
7
by: Andrew | last post by:
Hello, Is it possible for a file position indicator of an input stream to be greater than the size of a file? And if so could this cause fgetc to somehow write to the file? For example is it...
38
by: maadhuu | last post by:
does it make sense to find the size of a function ??? something like sizeof(main) ??? thanking you ranjan.
14
by: googler | last post by:
Is there any C library function that returns the size of a given file? Otherwise, is there a way in which file size can be determined in a C program? I need to get this for both Linux and Windows...
3
by: dice | last post by:
Hi, In order to use an external api call that requires a function pointer I am currently creating static wrappers to call my objects functions. I want to re-jig this so I only need 1 static...
4
by: Doug | last post by:
Hi, It looks like the only way to get a size of a file within csharp is to use FileInfo and the Length property. However that only returns the number of bytes in the file which is translating...
7
by: carterweb | last post by:
This is how I do it now. 1. Determine the dimensions of the rectangle. 2. Set a my font size to a fixed maximum size. 3. Apply the font my string and measure the string using the graphics...
5
by: sameer_deshpande | last post by:
Hi, I have DB2 UTF-8 database (codeset IBM-1252) on Windows 2000 Server. I need to store multi-byte contents. How do I calculate size of the column to store multi-byte information? F.ex: I...
36
by: James Harris | last post by:
Initial issue: read in an arbitrary-length piece of text. Perceived issue: handle variable-length data The code below is a suggestion for implementing a variable length buffer that could be used...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.