开发者

Making use of WCHAR as a CHAR?

GDI+ makes use of WCHAR instead of what the Win开发者_StackOverflow中文版API allows which is CHAR. Usually I can do:

char *str = "C:/x.bmp";

but how do I do this for wchar? I can't juse do

wchar_t *file = "C:/x.bmp";

Thanks


wchar_t *file = L"C:/x.bmp";

L introduces a wide string.

In Windows, it's customary to use macros that behave differently according to some preprocessor definitions. See http://msdn.microsoft.com/en-us/library/c426s321(VS.71).aspx

You would write:

_TCHAR *file = _TEXT("C:/x.bmp");


const wchar_t *file = L"C:/x.bmp";

This is according to C++ Standard 2.13.4/1:

<...>A string literal that begins with L, such as L"asdf", is a wide string literal. A wide string literal has type “array of n const wchar_t” and has static storage duration, where n is the size of the string as defined below, and is initialized with the given characters.

Note that you should use const qualifier here. The effect of attempting to modify a string literal is undefined (2.13.4/2).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜