Why sizeof(cin) is 144
and sizeof(cout) is 140
always
even after
cin.clear()
after cin.ignore() Its the Same
Why ??
Can anyone explain Me ??
Why sizeof(cin) is 144
and sizeof(cout) is 140
always
even after
cin.clear()
after cin.ignore() Its the Same
Why ??
Can anyone explain Me ??
sizeof has nothing to do with the number of characters in the buffers. What are you trying to do?
But Why its 144 and 140 ??
Whats teh Magic in these 2 Numbers.
No magic, just implementation detail.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
sizeof returns the number of bytes of memory an object (or type) occupies. So the cin object occupies 144 bytes of space and the cout object takes up 140 bytes of space. It might be different with a different library implementation.
The number depends on how the library implementors created the classes that cin and cout are objects of. I believe cin is a basic_istream and cout is a basic_ostream or something like that. Apparently on your platform those classes use that much space for their data.
Thanks got the Idea
But after cin.clear()
and cin.ignore(1000)
the buffer should get cleared compleately
But even after cin.clear() and cin.ignore I am seeing the same result.
Why ??
Like I said in the very first post, sizeof has absolutely nothing to do with buffers. They are completely unrelated.
sizeof is a compile time lookup based on the size of the class. It will never change for those two objects on your platform nobody what code you write.
What are you trying to do? Are you trying to find out how many characters are in the buffer?
Ah!
Ok.
Yes I am trying to Calculate the Size of the cin Buffer.So how can I do it ??
If I'm understanding your question ....
will yield the value you seek.Code:std::cin.rdbuf()->in_avail();
I believe that might not be reliable. I'm not sure there's a portable way to calculate how much data is in the buffer.
For cin, you probably want to read in a line up to a newline. User input is generally terminated by the <enter> key, so you will read in everything the user typed (in most cases). Then you can use that string as your own buffer.
Well, you can use the streambuf interface to find out how much data can be buffered. You cannot really use it to find out how much is buffered, because it may not be the only buffer.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law