【发布时间】:2020-05-09 02:45:20
【问题描述】:
#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;
}
我不明白为什么这行不能编译。
无法将“void”类型的表达式传递给可变参数函数;格式字符串中的预期类型为“int”。
【问题讨论】:
-
pop() 不返回值,因此没有任何内容可打印。您想使用 s.top() 打印并使用 s.pop() 将顶部项目从堆栈中弹出。
标签: c++