How to pass a string literal to a function which takes const std::wstring&
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...
精彩评论