扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

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

扬州沐宇科技
2024-02-28 12:38:12
c++

在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++"};

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

扫码添加客服微信