0

Cout copy

Hi Can we create copy of the cout object? Why?

23rd Sep 2024, 3:33 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
7 odpowiedzi
+ 4
Ketan Lalcheta do you mean something like this 🤔 https://sololearn.com/compiler-playground/cOo4nUuu8W9p/?ref=app
23rd Sep 2024, 3:39 PM
BroFar
BroFar - avatar
+ 3
If cout can be copied, then there is duplicate buffers and many stream copied. Not good for performance
23rd Sep 2024, 6:28 PM
Sharpneli
Sharpneli - avatar
23rd Sep 2024, 11:33 PM
Bob_Li
Bob_Li - avatar
+ 1
No you cannot copy any object defined in the istream or ostream because only one instance of them must have in your program and in their class, you will see that the copy constructor has been deleted if you look at the cpp source code
23rd Sep 2024, 5:59 PM
Sharpneli
Sharpneli - avatar
+ 1
No, you cannot create a copy of the cout object. The cout object is an instance of the std::ostream class, which is part of the C++ Standard Library. Stream objects like cout are designed to manage output streams and are not meant to be copied or assigned. This is because they manage resources such as buffers and file descriptors, which can lead to complex issues if duplicated. https://www.my-labcorp.com
25th Sep 2024, 10:12 AM
Gail207Martinez
0
BroFar need to understand that code first. Thanks for sharing it. Will take a look. I thought to have copy of cout in << operator overloading
23rd Sep 2024, 6:25 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Sharpneli why it is designed to have only single object ? Any specific logic to avoid more objects ?
23rd Sep 2024, 6:26 PM
Ketan Lalcheta
Ketan Lalcheta - avatar