#include <iostream>
#include <stack>
void convert(std::stack<char> &s, int n,int base)
{
static char digit[]={
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
};
while(n>0)
{
s.push(digit[n%base]);
n/=base;
}
}
int main() {
std::cout << "Hello, World!" << std::endl;
std::stack<char> s;
int n=89;
int base=2;
convert(s,n,base);
while(!s.empty())
{
printf("%c",s.pop());//this line is can not be compiled.
}
return 0;
}
enter image description here I do not understand why this line can not be compiled. Cannot pass expression of type 'void' to variadic function;expected type from format string was 'int'.
Check the signature of
std::stack::pop
: it returns void. You should usetop
to get the value andpop
to remove it.更正的代码: