【问题标题】:Write a c++ function that will prompt a user for an integer and convert it to binary and print in reverse order [duplicate]编写一个c ++函数,提示用户输入整数并将其转换为二进制并以相反的顺序打印[重复]
【发布时间】:2020-05-10 03:28:24
【问题描述】:

这是我的代码,我的错误信息是“error C4716: 'decToBinary': must return a value” 基本上,我希望用户输入一个整数并让程序以相反的顺序返回二进制扩展。我该如何解决这个问题?谢谢!

【问题讨论】:

标签: c++ binary integer reverse prompt


【解决方案1】:

错误信息非常清楚:您声明您的函数将返回 int,但您从未这样做过。

【讨论】:

  • 它被声明返回一个int而不是一个32个整数的数组。
  • @drescherjm 如何声明一个返回 32 个整数数组的函数?
  • 目前,您的函数没有返回任何内容。
  • 也许std::array<int,32> 虽然std::string 可能是一个更好的选择,如果你不能使用std::bitset 来代替这个。
猜你喜欢
  • 2020-11-09
  • 1970-01-01
  • 1970-01-01
  • 2021-12-30
  • 2021-07-03
  • 1970-01-01
  • 1970-01-01
  • 2021-05-14
  • 1970-01-01
相关资源
最近更新 更多