我正在尝试编写一个获取十进制数的函数并将其转换为二进制数(它应该返回它,因此我将其转换)。 问题是我一直得到这个错误:
"Practice.c: In function ‘std::string base2(int)’:
Practice.c:12:29: error: ‘stol’ was not declared in this scope
return (stol (number,0,2));"
这是我的代码,任何人都可以帮助我吗?
#include <iostream>
#include <string>
#include <stddef.h>
using namespace std;
long base2(int number) {
string result = "";
while(number/2 != 0) {
result = "" + (number % 2) + result;
number = number/2;
}
return (stol (number,0,2));
}
int main() {
cout << base2(3) << endl;
cin.get();
return 0;
}