I do not understand what to add to the arguments, the constructor in the method to call or return as a constructor. In general, the point is that I saved the product a (protein, carbohydrates, fat) and the output from the file should create an object product with the same data. I started doing this: but I understand that some kind of nonsense

friend std::ifstream& operator>>(std::ifstream& fin, product p1 ) { fin >> p1.Name; fin >> p1.Belok; fin >> p1.Gur; fin >> p1.Yglevod; (fin >> p1.Kkal).get(); return fin; } 

    1 answer 1

    Well, first you need to pass p1 by reference. Secondly, you have two options:
    i) you can use such an operator as you wrote, passing to it, for example, the product object created by default:

     product p; fin >> p; 

    ii) you can create a constructor with a stream parameter.

     product::product(istream&) { ... } ... product p(fin); 

    Do what suits you more :)

    • thanks, it seems like the second option will be simpler - Max.
    • Glad to help :) If you are satisfied with the answer - mark it as accepted ... - Harry