1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include <iostream> using namespace std; class Statistics { int *stack; int index; public: Statistics() { stack = new int[100]; index = 0; } ~Statistics() { delete[]stack; } Statistics& operator<<(int x); bool operator!(); void operator>> (int &x); }; Statistics& Statistics::operator<<(int x) { stack[index] = x; index++; return *this; } bool Statistics::operator!() { if (index == 0) return true; else return false; } void Statistics::operator>>(int &x) { x = stack[index - 1]; index--; } int main() { Statistics stack; stack << 3 << 5 << 10; while (true) { if (!stack) break; int x; stack >> x; cout << x << ' '; } cout << '\n'; } | cs |
'Programming > 명품 C++ Programming' 카테고리의 다른 글
명품 C++ Programming 실습문제 8장 1번 (0) | 2018.06.19 |
---|---|
명품 C++ Programming 8장 OpenChallenge (0) | 2018.06.19 |
명품 C++ Programming 실습문제 7장 9번 (0) | 2018.06.18 |
명품 C++ Programming 실습문제 7장 8번 (0) | 2018.06.18 |
명품 C++ Programming 실습문제 7장 7번 (0) | 2018.06.18 |