# define LOC_PATH_CONF_STR get_best_conf ()
Const char * conf_str []={
"A.c onf,"
"The biggest onf,"
"Arthur c. onf,"
", dc onf, "
Onf of e.c. with our fabrication: ", "
};
The inline const char * get_best_conf () {
Int length=sizeof (conf_str)/sizeof (conf_str [0]).
For (int I=0; I & lt; Length; I++) {
if (! Access (conf_str [I], F_OK)) {
Return conf_str [I];
}
}
Return conf_str [length - 1);
}
.cpp
Const char LOC_PATH_CONF []=LOC_PATH_CONF_STR;
The compiler complains:
Error: array, initializer must be an, initializer list or string literal
Const char LOC_PATH_CONF []=LOC_PATH_CONF_STR;
^
The LOC_PATH_CONF_STR define how to write? Thank you very much!
CodePudding user response:
Const char LOC_PATH_CONF []=LOC_PATH_CONF_STR///this sentence errors, the first array size must be determined at compile time, and you only at run time the function is to know how the return value of theCodePudding user response:
With vector< directly; string> Seems to be betterCodePudding user response:
The other array are only read-only initialized, but not assignmentSo
T array []=a function the way doesn't work
CodePudding user response:
Character array only at the time of initialization can appear to the left of the equals sign,Initialization is compile time term,
Compile time, running still have a long way to go, can't deal with executing statements/function,
So the initialization data can only be constant/constant expression/constant list/string literal
Things that don't need to run,