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?
Printable View
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?
Probably neither. This declares an array, named strings, of two std::string objects:
Code:std::string strings[2];
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:string [2];
Hence, a little more context (like posting the whole line of code) would be useful.Code:const char* string = "Hello world";
std::cout << string[2] << std::endl; //outputs the letter 'l'
Why to have an array of 2 string ? ( Something not good there)
Why not to have array with pointers to those strings ? :)
(Missunderstud question :( )
I don't see why pointers should get involved here. They certainly don't have to.
Just in case you might need different number of strings
Code:std::vector<std::string>