我有一个将 int 转换为二进制的函数,当从main
函数调用它时,它会给出错误binary: identifier not found
代码有什么问题?
#include <iostream>
using namespace std;
int main(){
int dec;
cin >> dec;
binary(dec);
return 0;
}
void binary(int decimal) {
int remainder;
if(decimal <= 1) {
std::cout << decimal;
return;
}
remainder = decimal % 2;
binary(decimal >> 1);
std::cout << remainder;
}