Overloading C++ Stream Insertion, Extraction Operators | C++ Programming Tutorial

Поділитися
Вставка
  • Опубліковано 14 гру 2024

КОМЕНТАРІ • 150

  • @hansandreas4743
    @hansandreas4743 8 років тому +75

    What the heck, this was very well explained! :D

    • @LearningLad
      @LearningLad  8 років тому +4

      +Hans Andreas Hestad
      thank you :)

    • @b3a7brewmp
      @b3a7brewmp 8 років тому +2

      heck yeah !..

    • @zahrazaidi4095
      @zahrazaidi4095 7 років тому

      sir what is the advantage of using stream insertion and extraction??

    • @kirandhamane6442
      @kirandhamane6442 7 років тому +1

      +Zahra Zaidi
      Here you can treat the objects as a variable.
      like if you want to set an attribute of the object you need to access the variable and then put it to cin>> but here you are putting the object in the cin. so you dont have to worry about if the variables are accessible or not.
      otherwise you have to implement a getter and setter method, to print or to set the attributes of the objects. although, getter and setter methods are more commonly used.

    • @zahrazaidi4095
      @zahrazaidi4095 7 років тому

      kiran dhamane thanks😊

  • @Chrisx7200
    @Chrisx7200 7 років тому +7

    Thank you! My professor made this much more complicated than it actually was. Good job.

  • @hollyd420
    @hollyd420 10 років тому +7

    Perfect!! Nice clean simple explanation...you rock!! Thank you!!

  • @buzzstudy
    @buzzstudy 11 місяців тому +1

    god bless you brother 😊solve the all doubts

    • @LearningLad
      @LearningLad  11 місяців тому

      Thanks
      I'm glad that my video helped you :)

  • @sourabroy7787
    @sourabroy7787 3 роки тому +1

    Thanks. Really helpful video 👍

  • @pritibasu920
    @pritibasu920 6 років тому +3

    We r very very grateful to you sir ☺

  • @kumarAjitesh
    @kumarAjitesh Рік тому

    Those who have a doubt that why didn't we make (>>,

  • @TusharSahu2813
    @TusharSahu2813 2 роки тому +1

    thanks for perfect explanation

  • @aryanmahajan7295
    @aryanmahajan7295 7 років тому +15

    anil shetty surely rocks! :)

  • @brahmadevs
    @brahmadevs 4 роки тому +1

    This comment section is so wholesome i love it!!

  • @melisabagcvan2928
    @melisabagcvan2928 3 роки тому +1

    Thank you so much.Finally someone told me properly.👍🏻🌸

  • @diana0205xd
    @diana0205xd 7 років тому +1

    I finally understood it, thanks dude!

  • @stefan4207
    @stefan4207 8 років тому +1

    Thank you Anil!

  • @ronakrawatofficial
    @ronakrawatofficial 4 роки тому +1

    Great man...😀😀

  • @matt-g-recovers
    @matt-g-recovers 3 роки тому +1

    I am impressed and grateful for such an outstanding explanation.
    Thank you.

  • @aryan7069_
    @aryan7069_ 3 роки тому +1

    Good one!

  • @mkalajo
    @mkalajo 10 років тому +7

    what the hack, that was a good explanation Anil :) . tnx mate!

  • @HK-no9wm
    @HK-no9wm 7 років тому +1

    Wonderfully explained! Thank you sir.

  • @pdxbound81
    @pdxbound81 5 років тому

    Excellent video! Thank you so much!

  • @abduldaim
    @abduldaim 4 роки тому +1

    Good Lecture

  • @JustinHerchel
    @JustinHerchel 7 років тому +1

    What a wonderful explanation!
    Thanks lad.

  • @KR3WSKATER32
    @KR3WSKATER32 9 років тому +1

    Great Video! I really appreciate the tutorial. *Thumbs up*

    • @LearningLad
      @LearningLad  9 років тому

      Eli Hammer
      thank you very much :)

  • @ngoctintran8583
    @ngoctintran8583 7 років тому +10

    Very helpful! But why we can't write like this:
    ostream operator

  • @mendselson2397
    @mendselson2397 8 років тому +2

    clear and concise!

  • @heybuddy_JAI_SHREE_RAM
    @heybuddy_JAI_SHREE_RAM 2 роки тому +3

    still very useful after more then 8 years🙃

  • @Gandhiboy
    @Gandhiboy 4 роки тому +1

    Thank you so much ❤️

  • @reliefpfeiler0815
    @reliefpfeiler0815 6 років тому +2

    Thanks a lot for this. Really helped me with my assignments :)

  • @yeshwantdesai4299
    @yeshwantdesai4299 6 років тому +1

    Thanks for the help!

    • @LearningLad
      @LearningLad  6 років тому

      My Pleasure.
      keep Learning :)

  • @husseinharajli3810
    @husseinharajli3810 4 роки тому +1

    Thanks!

  • @TheKingFisher98
    @TheKingFisher98 7 років тому +1

    Thanks Mate, that really helped me out!

  • @phuzaza_the_great7173
    @phuzaza_the_great7173 4 роки тому +1

    thanks a lot sir

  • @AlejandroRodriguez-wt2mk
    @AlejandroRodriguez-wt2mk 7 років тому +1

    enlighten, Thanks man.

  • @AxElKo440
    @AxElKo440 7 років тому +3

    Awesome explanation and interpretation!!! Thank you very much Anil. Keep rocking the programmer world!!!

  • @laibanadeem3242
    @laibanadeem3242 2 роки тому +1

    Thank you anil

  • @eliy5550
    @eliy5550 3 роки тому +1

    THANK YOU

  • @feitan8651
    @feitan8651 9 місяців тому

    thank you!

  • @ed.d8065
    @ed.d8065 6 років тому +1

    Thanks a lot man

  • @darshenjason3164
    @darshenjason3164 8 років тому

    Very well explained..helped alot..thanks bro! :D

  • @darkseeven
    @darkseeven 5 років тому +7

    what the hack, it was very simple explained

  • @anjaligupta-wh7gv
    @anjaligupta-wh7gv 7 років тому +8

    how we can overload stream extraction and extraction without friend functions

    • @623-x7b
      @623-x7b 4 роки тому +1

      You can make the variables that the friend function uses public and then the functions can be defined as a normal function.

  • @aniavetisyan1641
    @aniavetisyan1641 6 років тому +1

    Cool thanks !

    • @LearningLad
      @LearningLad  6 років тому

      My Pleasure.
      Keep Learning :)

  • @pramodkarmca
    @pramodkarmca 6 років тому +1

    Awesome ......

  • @vyasarambarran2136
    @vyasarambarran2136 10 років тому

    Excellent

  • @msh1233
    @msh1233 7 років тому +1

    Thanks a Billion ,,,,

  • @obtron
    @obtron 5 років тому +1

    very cool

  • @vivekmesuriya6357
    @vivekmesuriya6357 2 роки тому +1

    Whoes here to wach this video for hackerrank box it oprator overloading explaination

  • @stevenlee1726
    @stevenlee1726 9 років тому +6

    why u use reference operator before word operator? why why why?

    • @blondedadnan7637
      @blondedadnan7637 9 років тому +3

      +Steven Lee To prevent a copy, and pass back the exact stream that was passed in, we must return the stream by reference: ostream&

  • @amit80086
    @amit80086 3 роки тому +1

    Which compilor is using for c++. For program execution??

  • @johnc4624
    @johnc4624 3 роки тому

    Nice work.
    Perhaps pass a const Person for the output stream operator?

  • @jamesstark4136
    @jamesstark4136 3 роки тому

    Hello, i don't know if you check comments. Ii had a question. If i have my class defined in a header file, do I make the friend definition in or out of the class A
    {
    };
    Or if I need to put the definition in the .cpp file how do I do that without getting an error.
    Thank you for your time.

  • @priyashasingha5521
    @priyashasingha5521 2 роки тому

    Perfect

  • @sarathelayadath2565
    @sarathelayadath2565 4 роки тому +1

    I have a doubt.. since the reference of ostream has been passed to the function and any change will be reflected back to calling function, then why would you return reference variable?

    • @syedmuhammadabdullah1431
      @syedmuhammadabdullah1431 9 місяців тому

      because, a stream object is generally a file or screen, so it doesn't make sense calling a screen or a file by value.
      also, we want change to happen in our file/screen, that's the whole point of cout or any ostream output, so that's a good thing?

  • @xXZorganStudioXx
    @xXZorganStudioXx 8 років тому

    In microsoft visual studio, I cannot put in two parameters (i/ostream &input, Person &b), because it gers an error saying there is too many parameters.

  • @Impulse_Photography
    @Impulse_Photography 5 років тому

    can I overload the

  • @govindsankarmr2716
    @govindsankarmr2716 9 років тому +2

    its what the heck and not what the hack. i have seen this in number of ur videos. heck, not hack. apart from that awesome video. u r really good

    • @aryanmahajan7295
      @aryanmahajan7295 7 років тому +3

      dude , he's using a pun.

    • @RajSingh-rz7wx
      @RajSingh-rz7wx 7 років тому +4

      And Govind, it's "it's" not "its", so next time you go correcting others, be correct yourself.

  • @KueJiin
    @KueJiin 7 років тому

    Do I have to define those functions as friend function and make them global? Because whenever I use multiple ostream functions I get errors because of redefinition

  • @gowthamprabhu122
    @gowthamprabhu122 7 років тому +1

    Question..! The overload functions work even when the 'return output' and 'return input' statements are not included in their respective function definition's. So whats the point of having them anyways?

    • @shivakhatri3271
      @shivakhatri3271 6 років тому

      bro have you got your answer ?

    • @AY-uc5om
      @AY-uc5om 5 років тому

      Won't work as it is ostream and istream return type already...check out

  • @theonlyvhk28
    @theonlyvhk28 5 років тому

    Heck not hack....xplanation lvl 100

  • @PrakashBesra
    @PrakashBesra 9 років тому +1

    anil, why are you using reference before operator?...any reason?

    • @LearningLad
      @LearningLad  9 років тому

      +Prakash Besra
      yes.
      the operator functions should return the respected class type so that we can use them with cin and cout.

  • @mikelai7207
    @mikelai7207 7 років тому

    What you put & beside ostream?

  • @lubinbshahi7638
    @lubinbshahi7638 9 років тому +2

    why you use friend function rather than member function, can we use member function rather than friend function,if yes how we can use it

    • @LearningLad
      @LearningLad  9 років тому +17

      lubin B Shahi
      In operator overloading, if an operator is overloaded as member, then it must be a member of the object on left side of the operator.
      For example, consider the statement "ob1 + ob2" (let ob1 and ob2 be objects of two different classes). To make this statement compile, we must overload ‘+’ in class of ‘ob1′ or make ‘+’ a global function.
      The operators '' are called like 'cout > ob1'.
      So if we want to make them a member method, then they must be made members of ostream and istream classes, which is not a good option most of the time.
      Therefore, these operators are overloaded as global functions and to access the private and protected members of the class(in our tutorial Person class) we make them friend functions.
      Hope this helps :)

    • @willingtushar
      @willingtushar 7 років тому

      kasam se ....kya explain kiya h

  • @hassankamran3480
    @hassankamran3480 3 роки тому

    How are you calling private data members just by objects? Shouldn't we be using getter function instead?

  • @danlee3055
    @danlee3055 7 років тому

    question: so i was given a header file where I was to use a virtual function operator instead of friend function; how does this change the code?

  • @pockpock6382
    @pockpock6382 3 роки тому

    saved my ass trying to get the output of rgb values in % dec and hex

  • @mikelai7483
    @mikelai7483 3 роки тому

    May I know why we need & symbol beside ostream, what I mean is “friend ostream &operator >>(“

    • @mikelai7483
      @mikelai7483 3 роки тому

      Anil, can you reply on this ? Thanks you

  • @gastarbieter
    @gastarbieter 10 років тому +2

    why are using friend functions...rather than containing everything in your class?

    • @LearningLad
      @LearningLad  10 років тому +1

      hi gastarbieter,
      you can write everything in your class.
      Here i am just demonstrating how you can overload operators using friend functions, so that i don't have to make another specific tutorial on operator overloading with friend functions.

  • @Jayveersinh_Raj
    @Jayveersinh_Raj 3 роки тому

    What the heck, you saved my ass!! XD

  • @jeffreypenner7189
    @jeffreypenner7189 7 років тому

    I'm trying to use the ostream

  • @adebih8126
    @adebih8126 7 років тому

    char somechar;
    i need to overload >> to be able to input cin>>a; (and then is b=1) or cin>>a>>somechar>>b;
    how can i do it?

  • @samia1268
    @samia1268 4 роки тому

    why do i need to use the function as a friend
    cant i use it normally as a public function as istream& operator>>(Person& object);

  • @programmerStyle
    @programmerStyle 3 роки тому

    what if we put space in between characters than cin not working whats the solution then? plz ans

  • @notpythonics
    @notpythonics 8 місяців тому

    do you all memorize or understand why are we reteurnning by reference and the other implemations

  • @iAskShahram
    @iAskShahram 4 роки тому

    It did not work for me. it says
    "std::ostream& time::operator

  • @yousefayman4713
    @yousefayman4713 4 роки тому

    "binary 'operator' : 'type' does not define this operator or a conversion to a type acceptable to the predefined operator "
    I wrote the code and I got this error, can you help me please

  • @TheGoat-hr2qf
    @TheGoat-hr2qf 6 років тому

    i don't understand why should we return output or input?
    HELP!!!\

  • @جيمرمصري-ق5ق
    @جيمرمصري-ق5ق 5 років тому

    why do you need constructors in first place i mean you can use the overloaded insertion and extraction tha'ts their job

  • @ashutoshasthana4494
    @ashutoshasthana4494 9 років тому

    why do u use '&' in both function.....

  • @shahirabdullah5438
    @shahirabdullah5438 8 років тому

    pls try to explain why r u doing these rather than describing what r u doing it will make the video easier

    • @mukeshpathak7302
      @mukeshpathak7302 8 років тому

      Shahir ABD yiu cannot use > to take input for your objects. these insertion and extraction operators knows how to work with primitive datatypes.. like taking input of int char etc. but they don't know about user defined datatypes. i.e.. you cannot use >> or

    • @shahirabdullah5438
      @shahirabdullah5438 8 років тому

      thanks that helped i lot....i figured it out,,,,i was confused about the syntaxes he was using for overloading >> and

    • @mukeshpathak7302
      @mukeshpathak7302 8 років тому

      haha. yup that was confusing at first for me too.

  • @symbioticproductions2591
    @symbioticproductions2591 4 роки тому

    why do we use: & ?

  • @saadmumtazkhan1403
    @saadmumtazkhan1403 4 роки тому

    why are we passing by rederence

    • @notpythonics
      @notpythonics 8 місяців тому

      the real question is why are we returnning by reference and is it even a thing?
      and the answer for your qeustion is: we are passsing by reference for preformnce

  • @newera653
    @newera653 6 років тому

    Iam not intend to watch We gonna,we gonna video,

  • @dhu1090
    @dhu1090 3 роки тому +1

    why friend???!

    • @LearningLad
      @LearningLad  3 роки тому

      i was just demonstrating different ways of overloading operators.

  • @karahanozen8576
    @karahanozen8576 6 років тому

    Helal len saksocu

  • @AFTstorm
    @AFTstorm 8 років тому

    i dont understand this one bit

  • @awaistanvir3606
    @awaistanvir3606 6 років тому +1

    bhai plzz english ma na smjaya karo hindi ma btaya karo

    • @LearningLad
      @LearningLad  6 років тому

      c++ ki video series hindi me bhi jald hi banaunga.

  • @KarimNasser-y6k
    @KarimNasser-y6k Рік тому

    youa arent explaining anything

  • @KinzaZafar-x7s
    @KinzaZafar-x7s 10 місяців тому

    Bakwas +time waste

  • @agoraphobiccowboy2303
    @agoraphobiccowboy2303 4 роки тому

    Thanks a lot man! You've really helped with this video.