문제

I have a code on which the optimizing compiler always fails, with each launch.

char* GetWinSockVersion()
{
    char *tmpData = (char*)malloc(sizeof(wsaData.wVersion));
    _itoa_s<wsaData.wVersion>(wsaData.wVersion, tmpData, 10);
    return tmpData;
}

It does fail with the _itoa_s. I'm interested, why does it fail all times?

도움이 되었습니까?

해결책

You aren't using the function properly.

_itoa_s requires 4 arguments.

This function is meant to be used with c, for c++ you have stream.

Your code should be more like ( assuming wsaData.wVersion is a number )

char *tmpData = (char*)malloc(sizeof( char ) * 80 );
_itoa_s(wsaData.wVersion , tmpData , 80 , 10);

//_itoa_s(number to convert , target string, size of target string, number base);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top