作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个记录器,它有一条继承 std::stringstream
的消息.
当我想打印出消息时,我调用了一个接受消息的函数 const
:
void logger::log_message(message const & msg)
在该函数中,我想检查消息中是否写入了任何内容。如果没有,我可以忽略这个电话。我使用以下内容:
if(const_cast<message &>(msg).tellp() == 0)
{
return;
}
我不得不使用 const_cast<>()
因为tellp()
不是 const
.我想知道的是为什么检索当前搜索位置会对流产生副作用。我能理解 seekp()
这会改变位置,但不会改变 tellp()
.这可能是规范中的错误吗?
最佳答案
如果失败,tellp()
将更改对象的rdstate
。
参见: https://en.cppreference.com/w/cpp/named_req/UnformattedOutputFunction
关于c++ - 为什么 tellp() 是非常量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57237779/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 4 年前。
我已更改 my.cnf。并检查sql_mode使用下面的命令 select @@global.sql_mode; 它说, 我也尝试过 set global sql_mode=''; SET sql_m
首先,我有一个结构,它有一个值和一个默认值 struct S { int a = 1; }; 当 gcc 和 clang 都是 non-const/non-constexpr 时,可以默认构造
我是一名优秀的程序员,十分优秀!