c++

c++怎么创建字符串数组

小亿
225
2024-02-28 12:38:12
栏目: 编程语言

在C++中创建字符串数组可以采用以下方法:

  1. 使用字符数组:可以使用字符数组来创建字符串数组。例如:
char strArray[][20] = {"Hello", "World", "C++"};
  1. 使用std::vector:可以使用std::vector来创建动态大小的字符串数组。例如:
#include <vector>
#include <string>

std::vector<std::string> strArray = {"Hello", "World", "C++"};
  1. 使用std::array:可以使用std::array来创建固定大小的字符串数组。例如:
#include <array>
#include <string>

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

这些方法都可以用来创建字符串数组,具体选择哪种方法取决于需求和使用场景。

0
看了该问题的人还看了