【发布时间】:2020-03-31 09:18:00
【问题描述】:
我正在考虑从 snprintf 及其同类过渡到 fmtlib。 想象一下这个虚构的代码:
class CFoo
{
size_t m_szLen{0};
wchar_t m_pwcDst[123]{};
...
public:
void Bar(double dValue, uint8 u8TotDecimals)
{
m_szLen += swprintf_s(&m_pwcDst[m_szLen], _countof(m_pwcDst)-m_szLen, L"%.*f", u8TotDecimals, dValue);
}
};
如何在不复制 std::wstring 或 fmt_memory_buffer 的情况下将其转换为 fmtlib? 所以,我希望 fmt::format_to 使用我现有的缓冲区。
【问题讨论】:
-
你能在minimal reproducible example那里做你想要避免的副本吗?
-
类似这样的东西:``` std::wstring wstrTmp = fmt::format(L"{:.{}f}", dValue, u8TotDecimals); wcsncpy(m_pwcDst, _countof(m_pwcDst)-m_u32Len, wstrTmp.c_str(); m_u32Len += wstrTmp.length(); ```为什么'源代码'标记在这条评论中不起作用?!?应该是像源代码一样概述。
-
这不是minimal reproducible example。来自链接:“您的代码示例应该是......完整 - 提供其他人需要在问题本身中重现您的问题的所有部分”
-
本站使用问答格式,请不要在问题框中填写答案。您可以在答案框中写下答案。 (我已经回滚了)