C++参考的翻译或校对

做新年规划的时候,我说过要翻译C++常用类的参考。C++的参考,其实别人已经翻译完了,只是部分内容需要校对。由于网站结构中大量使用了模板,同一个函数只需要翻译一个地方,所以四天就弄完了。而且我没有翻译函数层级的页面,所以比较快。

C++的参考其实最需要翻译。因为C++为了填C继承过来的坑,标准库增加了很多用于替代的设施。而国内的教程更新缓慢,这份参考如果不翻译,我估计到了2020年也不会完全普及。

以下是校对完成的类,希望大家继续参与:

更多内容

数据结构:一个简单的栈模型

//学习数据结构后的一点心得体会

//stack.h文件:

#pragma once
#ifndef STACK_H
#define STACK_H

#include <stdexcept>
using namespace std;

template<class Entry, size_t Max>
class Stack
{
private:
size_t count;
Entry data[Max];

public:
Stack() {count = 0;}
bool empty() {return count == 0;}
void push(const Entry &e)
{
if(count == Max)throw exception("栈已满。");
data[count] = e;
count++;
}
void pop()
{
if(count == 0)throw exception("栈已空。");
count--;
}
Entry top()
{
if(count == 0)throw exception("栈已空。");
return data[count - 1];
}

};

#endif

//main.cpp文件:

#include "stack.h"

#include <iostream>
using namespace std;

int main()
{
    Stack<int, 100> psgs;
    int n;
    cout << "请输入游客人数:" << endl;
     cin >> n;
    cout << "按顺序输入乘客编号:" << endl;
    for(int i = 0; i < n; i++)
     {
         int item;
         cin >> item;
        psgs.push(item);
    }
    cout << "乘客下车次序是:" << endl;
    while(!psgs.empty())
    {
        cout << psgs.top() << ' ';
        psgs.pop();
    }
    cout << endl;
    system("pause");
    return 0;
}