setbase(8) 和 std::cout<
发布于 2024-10-11 04:11:08 字数 217 浏览 0 评论 0 原文

std::cout<std::cout< 它们等价吗?

另外,std::cout.oct的目的是什么?

Whats the difference between std::cout<<std::setbase(8)<<32; and std::cout<<std::oct<<32; Are they equivalent?

And also, what is the purpose of std::cout.oct??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不语却知心 2024-10-18 04:11:08

std::oct 将 str 流的基字段格式标志设置为 oct。

std::setbase 将基字段格式标志设置为可能的值之一:十六进制、十进制或八进制,具体取决于基本参数的值。

我认为最大的区别是 setbase 接受一个参数,所以你可以向它传递一个包含你想要的数字基数的变量。而不是使用一堆 if 语句来检查变量并使用 dec、oct 或 hex。

但我不确定 std::cout.oct 。

std::oct Sets the basefield format flag for the str stream to oct.

std::setbase Sets the basefield format flag to one of its possible values: hex, dec or oct depending on the value of the base parameter.

I think the big difference is that setbase takes an argument so you could pass it a variable containing the numerical base you want. Instead of having a bunch of if statements to check the variable and use dec, oct or hex.

I'm not sure about std::cout.oct though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文