How many chars or characters , or bytes of data std::cout can output at once?
Asked Answered
M

2

1

I am learning C++, so you are very right to assume that I am new to C++ and programming as well.

I am trying to understand iostream library, not the whole, but the things that newcomers must know before jumping into another topic. My understanding of std::cout is that it is a variable that holds bunches of chars or value of other variables for outputting into the console.

Now I am curious to know maximum number of chars as a string--giving directly(like std::cout <<"hello\n"--it(std::cout) can output to the console.

Middaugh answered 18/8, 2020 at 14:52 Comment(2)
std::cout is not limited, but a string literal is.Mcelroy
The buffer used by std::cout is limited and it's size is implementation defined. Also, there may be layers and multiple buffers, depends on the Operating System. You can always write a test program to get information about your system.Galbreath
T
3

There is no specified limit. There may be a practical implementation specific limit. Most likely, it will be way more than you'll need.

Note that std::cout streams to standard output. While that is often displayed in console, that is not necessarily the case.

Torn answered 18/8, 2020 at 14:55 Comment(0)
G
2

Your understanding of std::cout is not quite correct. std::cout is a variable but it doesn't hold characters, it outputs characters(typically to the console).

Now std::cout is usually buffered, which means it doesn't output characters immediately but only when its buffer is full or when it has a complete line of characters. But this process happens automatically, and I don't think that is quite what you meant by 'holds chars'.

Goodbye answered 18/8, 2020 at 14:56 Comment(3)
Thank you for correcting the contrary in my understanding. So what is the maximum size of std::cout's buffer?Middaugh
@Middaugh If the buffer becomes full, it will automatically be flushed to whatever device your standard output connects to (usually a terminal) and std::cout won't be bothered. The quantity of output is not limited by std::cout in any way. It may be limited by the connected device. For example, if you stream your binary's output to a file, the hard drive may become full.Brogan
So the data size that std::cout is going to output depends on the output devices like console, harddrive(when wrting using cout), or monitor. If the data is string (as @Mcelroy pointed that out) it has a limit on how long a string can be, but it is not a limitation of std::cout, rather the limitation of string implimentation in C++. Please correct me if I am wrong.Middaugh

© 2022 - 2024 — McMap. All rights reserved.