c++arraysstring

is string array possible in c++?


As far as I know,in C++ string is itself an array of char.

So my question is:
Is it possible to have a String array in C++?

If yes please let me know the way to declare/handle it.


Solution

  • Of course it is:

    // Requires <string> and <vector> includes
    std::vector<std::string> foo = {"this", "is", "a", "string", "array"};
    

    or

    // Requires <string> and <array> includes
    std::array<std::string, 3> foo = {"if", "you", "must"};
    

    As a rule of thumb, always use std::vector unless you can think of a very good reason not to.