Article View: borland.public.cppbuilder.nativeapi
Article #9579Re: How to determine the Number of Elements in an Array?
From: Andrue Cope [TeamB]
Date: Mon, 05 Jul 2004 08:10
Date: Mon, 05 Jul 2004 08:10
25 lines
1651 bytes
1651 bytes
PC Hua wrote:
> I have something like...
> std::string SomeStr[]={"a","b","c"};
> I want to run through all elements. How can I get the size of the
> list (number of elements)?
Ah...that's an odd bit of code. It produces an array of three
"std::string"s and puts "a" in the first one, "b" in the second and "c"
in the third. Is that what you intended?
As for determining the number of elements you can use "sizeof( SomeStr
)/sizeof( std::string )" which will return 3. Note however that this
size will not change as the strings themselves change.
Are you sure you aren't after one string containing "abc"? If you are
then the syntax would be:
std::string SomeStr="abc";
--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
Technical Details
Message-ID:
<40e90cfb$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<opsam505lcpmxkmr@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: "Andrue Cope [TeamB]" <no.spam@spammy.com> Subject: Re: How to determine the Number of Elements in an Array? Newsgroups: borland.public.cppbuilder.nativeapi References: <opsam505lcpmxkmr@newsgroups.borland.com> User-Agent: XanaNews/1.16.3.1 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 NNTP-Posting-Host: 217.207.223.34 Message-ID: <40e90cfb$1@newsgroups.borland.com> Date: 5 Jul 2004 01:10:35 -0700 X-Trace: newsgroups.borland.com 1089015035 217.207.223.34 (5 Jul 2004 01:10:35 -0700) Lines: 25 X-Authenticated-User: acope Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail