Tuesday, July 14, 2009

Does C++ allow you to declare arrays of strings?

Yes.

Does C++ allow you to declare arrays of strings?
Yes.


In C++ string is array of charecter.


So array of string is indeed 2D array of charecter( or array of charecter type pointer.)
Reply:C++ doesn't have a string object built in.


The Standard Template Library (STL) has a string class and you can declare an array of those.


If you are using Microsoft C++ with MFC, you can declare an array of CString objects.


You also can define your own string class or use and array of arrays of char.
Reply:yes but you need to include a special library. I believe the following would work:





#include %26lt;string%26gt;





string myString [100];
Reply:What you can do is declare a class or a struct of a string, and then declare that class/struct as an array.





E.G.





struct MyStringStructure


{


const char* String;


/*Maybe instead:


char String[256];*/


};





MyStringStructure* g_StringArray;





There are also other ways of doing this, but this seems like the best. I also believe that Microsoft C++ has integrated some sort of string class, but it is very difficult to use from what I understand.


No comments:

Post a Comment