Re: std::setlocale(...) return value ??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux