我的"程序语言"(C++)存在很大问题.我想打印一堆字符串.
void show(stack<string> stos) {
while (!stos.empty()) {
cout << stos.pop() << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
pop()只从堆栈中删除顶部元素并将其抛弃.它返回void(没有),你cout显然无法用它打印.你需要:
void show(stack<string> stos)
{
while(!stos.empty()) {
cout << stos.top() << endl;
stos.pop();
}
}
Run Code Online (Sandbox Code Playgroud)