Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对称为 C++ 的“程序语言”有一个大问题。我想打印字符串堆栈。
void show(stack<string> stos) { while (!stos.empty()) { cout << stos.pop() << endl; } }
pop()仅从堆栈中删除顶部元素并将其丢弃。它返回(什么都没有) ,显然void你不能用 打印它。cout你需要:
pop()
void
cout
void show(stack<string> stos) { while(!stos.empty()) { cout << stos.top() << endl; stos.pop(); } }
pop不返回删除的值。您必须首先访问top()以获取值,然后调用pop()以摆脱它。
pop
top()