-
January 30th, 2009, 05:10 AM
#1
Can you have an array of strings?
string [2];
does this create two strings or a string of 2 characters?
If the latter how do you make it work as an array of strings?
Last edited by E-man96; January 30th, 2009 at 05:14 AM.
-
January 30th, 2009, 05:13 AM
#2
Re: Can you have an array of strings?
Probably neither. This declares an array, named strings, of two std::string objects:
Code:
std::string strings[2];
-
January 30th, 2009, 06:19 AM
#3
Re: Can you have an array of strings?
It depends what the code is that you posted - laserlight has most likely given you the most appropriate answer.
But anyhow just posting
isn't the most helpful code snippet - for one thing, it is not valid code from a declaration point of view. Therefore it could mean more than one thing. For example, it could be the use of operator[]. e.g.
Code:
const char* string = "Hello world";
std::cout << string[2] << std::endl; //outputs the letter 'l'
Hence, a little more context (like posting the whole line of code) would be useful.
-
January 30th, 2009, 02:47 PM
#4
Re: Can you have an array of strings?
Why to have an array of 2 string ? ( Something not good there)
Why not to have array with pointers to those strings ?
(Missunderstud question )
Last edited by ulumulu; January 30th, 2009 at 04:26 PM.
Share and always try to give back more.
-
January 30th, 2009, 03:47 PM
#5
Re: Can you have an array of strings?
I don't see why pointers should get involved here. They certainly don't have to.
-
January 30th, 2009, 05:13 PM
#6
Re: Can you have an array of strings?
Just in case you might need different number of strings
Code:
std::vector<std::string>
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|