C++中左移操作符的重载
生活随笔
收集整理的這篇文章主要介紹了
C++中左移操作符的重载
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 1 C++中左移操作符的重載
1 C++中左移操作符的重載
我們可以重載左移操作符,將變量或者常量左移到一個對象中!
示例代碼:
#include <stdio.h>const char endl = '\n';class Console { public:Console& operator << (int i){printf("%d", i);return *this;}Console& operator << (char c){printf("%c", c);return *this;}Console& operator << (const char* s){printf("%s", s);return *this;}Console& operator << (double d){printf("%f", d);return *this;} };Console cout;int main() {cout << 1 << endl;cout << "D.T.Software" << endl;double a = 0.1;double b = 0.2;cout << a + b << endl;return 0; }參考資料:
總結
以上是生活随笔為你收集整理的C++中左移操作符的重载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 考不上高中可以当兵吗?
- 下一篇: C++标准库与STL简介