gpt4 book ai didi

c++ - 使用 Pantheios 登录时如何利用现有的 operator<< 重载?

转载 作者:行者123 更新时间:2023-11-30 03:09:10 25 4
gpt4 key购买 nike

如果有大量用户定义的类型来实现 operator<<写入 std::ostream .在使用 Pantheios 记录我的类型时如何使用这些?

最佳答案

您需要为自己的数据类型提供“垫片”。这似乎是关于如何执行此操作的文档:http://www.pantheios.org/tutorials_code.html#types_without_shims .示例:

namespace stlsoft
{
inline stlsoft::shim_string<char> c_str_data_a(Point const& point)
{
stlsoft::shim_string<char> s(101);

int cch = ::sprintf(s, "{%d, %d; area=%d}",
point.x, point.y, point.x * point.y);

s.truncate(static_cast<size_t>(cch));

return s;
}
inline size_t c_str_len_a(Point const& point)
{
char buff[101];

return static_cast<size_t>(::sprintf(&buff[0], "{%d, %d; area=%d}",
point.x, point.y, point.x * point.y));
}

} // namespace stlsoft

在这种情况下,可以直接将类型传递给日志语句:

pantheios::log_ERROR("Point: ", point);

祝你好运!

关于c++ - 使用 Pantheios 登录时如何利用现有的 operator<< 重载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4335043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com