John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
How is FirstName declared?
Does it look something like this:
std::string FirstName;
Or is it like this:
char FirstName[] = "Blah blah";
The latter will require what I edited into my post later (that is, strlen).
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
Ah, I see what you're getting at.
Well, you could use the vector array example, or you could use a const to keep track of the array size:
const int ARRAY_SIZE = 10;
string FirstName[ARRAY_SIZE];
// ...
for (int i=0; i < ARRAY_SIZE; i++) {
// ...
}
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
srting FirstName[10];
Do you mean to make
1) an array of 10strings
2) a string to hold 10 characters?
If 1, you reference the length with stringname[index].length()
If 2, you create the string with char stringname[10] then reference the length with strlen(stringname)
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
an array to hold 10 strings
stringname.length() does not work
Of course it doesn't, you want the actual size of the container.:rolleyes:
I.e if there is ten strings in there you want it to return 10. As mentioned before if you declare it as
string stuff[10]
Just do for (int i=0; i<10; i++)
If you were using a vector of strings you could have done. for ( int i=0; i < myVector.size(); i++)
Again mentioned before.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Did you stop reading my post after the questions? I followed it with the answers... :rolleyes:
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943