0

I was reading a project in which I found this line. I am not able to understand what this line does.

std::ofstream("img_preview.jpg", std::ios::binary) << std::ifstream("img.jpg", std::ios::binary).rdbuf();

I tried to search this kind of syntax but couldn't find proper reference. Please help me out.

kiner_shah
  • 3,939
  • 7
  • 23
  • 37
  • 3
    Basically it's copying a file, https://en.cppreference.com/w/cpp/io/basic_ostream/operator_ltlt, it's item #9 – john May 27 '20 at 10:59
  • 1
    That line is doing a lot of things. Opening an output file stream in binary mode as an anonymous object. Opening an input file stream in binary mode as an anonymous object. Output via `<<` the input file's read buffer to the output stream. Destructing both anonymous objects. Which part do you not understand? – Eljay May 27 '20 at 11:10
  • I didn't understood the syntax at all. Thanks john and Eljay. :-) – kiner_shah May 27 '20 at 12:22

0 Answers0