Is it really wrong to think of a stream as a set of continuous characters (or whatever is in them) since it's really how it works (or do I have that all wrong)?
I just stumbled across the in_avail() on this site, and the example shows that it should work, but doesn't work as intended on my system. Aside from unsyncing with stdio, what alternatives exist aside from stepping through the stream? I just look at that as not being as effective as what I'd like to do with it.
My first scenario:
When I ask a user for a character, I want to see if they input a string and set the failbit manually that way.
My second scenario:
It would be nice to specify the number of items in the stream when using cin.ignore() instead of just saying to add a whole new header file just to use limits or instead of using a magic number (like 80 when I demonstrate).
My third scenario:
When asking a user to enter an int and they enter a floating point value instead, I would like to check against that. I believe this is the same situation as my first scenario though.
Maybe I'm just refusing to do the simple solution and use the get function like I probably should be, but it doesn't look nice and I don't feel that's exactly what it's meant for.
Cubbi wrote: |
---|
But it does not apply to std::cin since it is forbidden to buffer anything |
If that's the case, why is it that when you enter a string with spaces and don't use cin.getline, it overflows into the next cin call? There has to be a buffer of some sort there. Is it just not available to us?