如何在C++中声明字符串数组?

Tha*_*eeb 4 c++ string

在C++中如何声明字符串数组?我试图将它声明为数组,char但这不正确.

unw*_*ind 16

#include <string>

std::string my_strings[100];
Run Code Online (Sandbox Code Playgroud)

那就是C++,使用STL.在C中,你会这样做:

char * my_strings[100];
Run Code Online (Sandbox Code Playgroud)

这读作"我的字符串是100个指向char的指针的数组",后者是字符串在C中的表示方式.


sou*_*rge 13

我宁愿建议在几乎所有情况下都使用字符串向量:

#include <string>
#include <vector>
std::vector<std::string> strings;
Run Code Online (Sandbox Code Playgroud)