Bản chất của toán tử >> <> << C++ (toán tử xuất nhập)

  1. #include <iostream>

  2. using

    namespace

    std

    ;

  3. #include <conio.h>

  4.  

  5.  

  6. class

    nguoi

  7. {

  8. private

    :

  9.    

    int

    chieucao

    ;

  10.    

    int

    cannang

    ;

  11. public

    :

  12.    

    friend

    istream

    &

    operator

    >>

    (

    istream

    &

    is,nguoi

    &

    a

    )

    ;

  13. }

    ;

  14. istream

    &

    operator

    >>

    (

    istream

    &

    is,nguoi

    &

    a

    )

  15. {

  16. cout

    <<

    “Nhap chieu cao va can nang :”

    ;

  17. return

    cin

    >>

    a.

    chieucao

    >>

    a.

    cannang

    ;

    a.a.

  18. }

  19.  

  20. class

    giaovien

    :

    public

    nguoi

  21. {

  22. private

    :

  23.    

    int

    luongthang

    ;

  24. public

    :

  25.    

    friend

    istream

    &

    operator

    >>

    (

    istream

    &

    is,giaovien

    &

    a

    )

    ;

  26. }

    ;

  27. istream

    &

    operator

    >>

    (

    istream

    &

    is,giaovien

    &

    a

    )

  28. {

  29. cin

    >>

    (

    nguoi

    &

    )

    a

    ;

    // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    nguoi

  30. cout

    <<

    “Nhap vao luong thang : “

    ;

  31. return

    cin

    >>

    a.

    luongthang

    ;

    a.

  32. }

  33.  

  34. void

    main

    (

    )

  35. {

  36.     giaovien x

    ;

  37. cin

    >>

    x

    ;

  38.     getch

    (

    )

    ;

  39. }