开发者

How to pass a string literal to a function which takes const std::wstring&

开发者 https://www.devze.com 2022-12-16 16:44 出处:网络
I have a function which takes const std::wstring& font_family, i.e. Font Font::CreateFont(const std::wstring& font_family){ ... }

I have a function which takes const std::wstring& font_family, i.e.

Font Font::CreateFont(const std::wstring& font_family){ ... }

By question is how can I call that funcion by passing a string literal (e.g monospace)?

I tried

CreateFont("monospace");
CreateF开发者_运维技巧ont("std::wstring("monospace") );

Both does not compile. Any one have better idea?

Thank you.


Try:

CreateFont(L"monospace");

The leading "L" directs the compiler to generate a wide (wchar_t) string.


std::wstring s(L"Monospace");
CreateFont(s);

the ctor for wstring doesn't accept narrow characters, only wides...

0

精彩评论

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

关注公众号