我不确定以下代码是如何工作的.我以为你必须这样做,{'h', 'e' ...etc...}但似乎工作正常.另一方面,如果你这样做std::array<const char*只会向数组添加一个元素.字符串文字初始化是否有特殊规则?
std::array<char, strlen("hello world!") + 1> s = {"hello world!"};
for (size_t i = 0; i < s.size(); ++i)
{
std::cout << s[i];
}
Run Code Online (Sandbox Code Playgroud)