votre fonction est appelée « à la chaîne », et il est en effet plus facile (et plus universel) pour convertir en une chaîne de convertir « en LPCWSTR »:
template< typename OStreamable >
std::wstring to_string(const OStreamable& obj)
{
std::wostringstream woss;
woss << obj;
if(!woss) throw "dammit!";
return woss.str();
}
Si vous avez une API qui a besoin d'un LPCWSTR
, vous pouvez utiliser std::wstring::c_str()
:
void c_api_func(LPCWSTR);
void f(long l)
{
const std::wstring& str = to_string(l);
c_api_func(str.c_str());
// or
c_api_func(to_string(l).c_str());
}
Il fonctionne très bien. Merci beaucoup. –