7.1.8 Cải tiến toán tử << (1)
Chúng ta xem xét 2 cách khác nhau để sử dụng toán tử “<<“: một được thực hiện bởi chúng ta và một lấy từ các […]
|
1 2 3 |
void Stack::operator>> (int &v) { v = pop(); } |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include "mystack_02.h" #include <iostream> using namespace std; int main(void) { int i = 2; Stack stk; stk << 1; stk << 2 * i; stk << i; stk >> i; cout << i << endl; stk >> i; cout << i << endl; stk >> i; cout << i << endl; return 0; } |
|
1 2 3 |
void Stack::operator<< (int v) { push(v); } |
Copyright © 2026 CppDeveloper by Phạm Minh Tuấn (SHUN)