On 2017/5/4 16:33, Papa wrote:
According to the C++ Reference setlocale(...) returns a 'char*',
however, when trying to assign this function's return value to another
'char*', it creates an run time error.
Here is my example:
<snip>
void jme::Locale::setGlobalLocale(const std::string& str){
char* arg = new char[str.length()+1];
strcpy(arg, str.c_str()); // const char* to char* -- Works
char* cp = new char[1024];
strcpy(cp, std::setlocale(LC_ALL, arg)); // char* to char* -- Does
not work ??
delete arg;
delete cp;
}
</snip>
The code compiles, but as I said before it does not run.
What am I missing? How can I solve this problem?
This is a RTFM question. `setlocale()` returns a null pointer in case of
failure and in that case you are passing a null pointer to `strcpy()`.
--
Best regards,
LH_Mouse