开发者

Using wmemset in c++

While using wmemset api (http://msdn.microsoft.com/en-us/library/1fdeehz6(VS.80).aspx) for the count parameter should I have to multi开发者_如何学Cply the length of the target string by 2 and provide or will wmemset will itself take care of the conversion?


The answer is no. They have an example on the page you linked to:

#include <wchar.h>
#include <stdio.h>

int main( void )
{
    wchar_t buffer[] = L"This is a test of the wmemset function";

    wprintf( L"Before: %s\n", buffer );
    wmemset( buffer, '*', 4 );
    wprintf( L"After:  %s\n", buffer );
}

Output:

Before: This is a test of the wmemset function
After:  **** is a test of the wmemset function

Of course, the destination must have enough space (sizeof(wchar_t) times the number of characters being written to).


No, you should not. Length is in string characters (wchar_t), not in bytes (char). You need to pass the number of wide characters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜