🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #9495

Re: How to determine the Number of Elements in an Array?

#9495
From: Bob Gonder
Date: Tue, 06 Jul 2004 00:45
40 lines
2330 bytes
PC Hua wrote:

>Since I'm using the array combined with 'map' there's another problem. I'm 
>trying to process a XML file. Although the array is static I want to keep 
>it easy to be modified.
>std::string	A_Attrib[]={"a0","a1","a2"};
>std::string	B_Attrib[]={"b0"};
>
>typedef	map< std::string, std::string*>	NodeType;
>NodeType	Node;
>
>// Initialize
>Node["A"]= A_Attrib;
>Node["B"]= B_Attrib;
>
>i.e. when "A" comes in it will go through A_Attrib, B_Attrib for "B".
>Unfortunately, sizeof doesn't work on Node["A"] because it's not an array 
>of the elements which I want to count.
>
>It sounds very complicate :-) Maybe someone knows a better way.

It's been over 10 years since I've looked at STL, so this is just a
nudge in the (right?) direction...

Doesn't the STL have an array class? Perhaps list, or at least vector?
That knows the number of current elements?

Might not A_Attrib be a list of string?
And might not NodeType then be a map of list of string?

Then, there is the "C" way, which someone already suggested:
std::string	A_Attrib[]={"a0","a1","a2",NULL};
std::string	B_Attrib[]={"b0",NULL};

Go until you reach NULL.
	string*s = Node["A"]
	while( *s != NULL )
	{	use s;
		++s;
	};
Technical Details
Message-ID: <sqsje05j61hjn6jl2a3rh4jtdkboir5eb5@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <opsam505lcpmxkmr@newsgroups.borland.com> <40e9759b$1@newsgroups.borland.com> <opsaoursodpmxkmr@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,befc51f674d02011
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: How to determine the Number of Elements in an Array?
Date: Mon, 05 Jul 2004 17:45:47 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <sqsje05j61hjn6jl2a3rh4jtdkboir5eb5@4ax.com>
References: <opsam505lcpmxkmr@newsgroups.borland.com> <40e9759b$1@newsgroups.borland.com> <opsaoursodpmxkmr@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.34.194.43
X-Trace: newsgroups.borland.com 1089074745 69.34.194.43 (5 Jul 2004 17:45:45 -0700)
Lines: 42
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail