压完三个之后有几个
运行下面这段程序:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
template <class T>
struct Stack {
vector<T> items;
void push(const T& x) { items.push_back(x); }
T pop() {
T top = items.back();
items.pop_back();
return top;
}
T peek() const { return items.back(); }
bool is_empty() const { return items.empty(); }
int size() const { return (int)items.size(); }
};
int main() {
Stack<string> s;
for (const string& x : {"阿岚", "小满", "阿泰"}) s.push(x);
cout << s.size() << endl;
}
(本题用 g++ -std=c++17 -O0 编译。)
全部评论