W3School TIY Editor

  • W3School 在线教程
  • 改变方向
  • 暗黑模式
​x
 
#include <iostream>
#include <stack>
using namespace std;
​
int main() {
  // 创建字符串栈 cars
  stack<string> cars;
​
  // 向栈中添加元素
  cars.push("Volvo");
  cars.push("BMW");
  cars.push("Ford");
  cars.push("Tesla");
  
  // 访问栈顶元素
  cout << cars.top();
  return 0;
}