C++ String Array: How to Create (3 Methods)

In C++, you can create a string array using the following method:

  1. Using character arrays: You can use character arrays to create arrays of strings. For example:
char strArray[][20] = {"Hello", "World", "C++"};
  1. You can create a dynamically-sized array of strings using std::vector. For example:
#include <vector>
#include <string>

std::vector<std::string> strArray = {"Hello", "World", "C++"};
  1. You can use std::array to create a fixed-size array of strings. For example:
#include <array>
#include <string>

std::array<std::string, 3> strArray = {"Hello", "World", "C++"};

All of these methods can be used to create an array of strings, the specific choice of method depends on the requirements and use case.

bannerAds