Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 函数返回指向nothing的指针?_C++ - Fatal编程技术网

C++ 函数返回指向nothing的指针?

C++ 函数返回指向nothing的指针?,c++,C++,我有一个函数可以将char*转换为wchar.*。但事实并非如此——我只有奇怪的3个空格的字符串。这是因为GetWC返回指向不存在字符串的指针吗 const wchar_t *GetWC(const char *c) { size_t cSize = strlen(c)+1; std::wstring wc( cSize, L'#'); mbstowcs( &wc[0], c, cSize ); return wc.c_str(); } int _tm

我有一个函数可以将char*转换为wchar.*。但事实并非如此——我只有奇怪的3个空格的字符串。这是因为GetWC返回指向不存在字符串的指针吗

const wchar_t *GetWC(const char *c)
{
    size_t cSize = strlen(c)+1;
    std::wstring wc( cSize, L'#');
    mbstowcs( &wc[0], c, cSize );
    return wc.c_str();
}


int _tmain(int argc, _TCHAR* argv[])
{
    char *g ="aaa";

    const wchar_t* f= GetWC(g);
    wcout<<f;

    return 0;
}
const wchar\u t*GetWC(const char*c)
{
尺寸=斯特伦(c)+1;
std::wstring wc(cSize,L'#');
mbstowcs(和wc[0],c,cSize);
返回wc.c_str();
}
int _tmain(int argc,_TCHAR*argv[]
{
char*g=“aaa”;
常数wchar_t*f=GetWC(g);

wcout
wc.c_str()
GetWC
返回后无效。
wc
是一个局部变量

Return
std::wstring
按值,以保留其值。任何真正需要指针的人都可以自己调用
c_str()