Yes, it does:
#include <string>
int main(void)
{
static const size_t Capacity = 12;
std::string Months[Capacity] = { "Jan", "Feb", "Mar", "April", "May",
"June", "July", "Aug", "Sep", "Oct",
"Nov", "Dec" };
}
Your errors were probably related to something else. Did you remember to use std::
? Without knowing, it could be anything. Was Capacity
the wrong size? Etc.
Note your code wasn't actually a constant array. This is:
#include <string>
int main(void)
{
static const size_t Capacity = 12;
static const std::string Months[Capacity] = { "Jan", "Feb", "Mar", "April",
/* ^^^^^^^^^^^^ */ "May", "June", "July", "Aug",
"Sep", "Oct", "Nov", "Dec" };
}
Also, you don't actually need Capacity
, as others will show, and you could use const char*
if you'd like, though you lose the std::string
interface.