Public Group

[C++] Multidimensional Arrays question

This topic is 3658 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey guys, I was wondering if there was any way that I could access the size (or length) of a string element inside a multidimensional array. I tried using (ARRAY[x][y]).size to access the size, but it gave me a compile error. I did get past this problem by using a switch statement, but I was just wondering, is there any way to access the size of the string? Thanks, Kai.

Share on other sites
You can (and probably should) use Boost.MultiArray. It's designed to handle exactly what you're after. Also, its overhead is minimal if existent at all.

Example:
boost::multi_array<float, 3> my_array(boost::extents[12][13][14]);my_array[0][0][0] = 4;

Share on other sites
You mean, you have a multidimensional array of strings, and you want to find the length of a particular string in that array? If you're talking about std::strings, then no problem:
std::string array[10][10];//do stuff that puts stuff in the strings hereint size = array[3][6].size();

Share on other sites
HAHAHA oops. I made a very careless error. As stated above..I used array[x][y].size...I forgot the parenthesis...

Thanks for the answer and I'll look more into Boost.MultiArray

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 10
• 12
• 9
• 12
• 37
• Forum Statistics

• Total Topics
631420
• Total Posts
2999987
×