Hello
I need a static string array in my program for instance:
Is there any better/other way to do this in c++, or I have to do it the same as in c?Code:char *day[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
Printable View
Hello
I need a static string array in my program for instance:
Is there any better/other way to do this in c++, or I have to do it the same as in c?Code:char *day[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
... or depending on how it's usedCode:#include <string>
std::string days[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
... but of course that option also works in C, as well.Code:enum days { SUN, MON, TUE, WED, THU, FRI, SAT };
Or:
I am not sure \0's are needed but I added them so there can be no problem with the code.Code:char day[7][4]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
They're not needed. On the contrary, you just created compile-time buffer overflows, and a good compiler would refuse to compile it.