Why isn't this a Contradiction? i.e What did I understand wrong?

This is a discussion on Why isn't this a Contradiction? i.e What did I understand wrong? within the C++ Programming forums, part of the General Programming Boards category; The book "Thinking in C++(V2)" gives something like the following example: Code: int main() { ifstream in("a.cpp"); while(in.get(*cout.rdbuf())) in.ignore(); return ...

  1. #1
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498

    Why isn't this a Contradiction? i.e What did I understand wrong?

    The book "Thinking in C++(V2)" gives something like the following example:
    Code:
    int main() 
    {
        ifstream in("a.cpp");
        while(in.get(*cout.rdbuf()))
            in.ignore();
        return 0;
    }
    It compiles and works correctly.

    But my <streambuf> file says:
    Quote Originally Posted by streambuf
    * -# Stream buffers can impose various constraints on the sequences
    * they control. Some constraints are:
    * - The controlled input sequence can be not readable.
    * - The controlled output sequence can be not writable. <------------- [THIS is the line I'm talking about]
    * - The controlled sequences can be associated with the contents of
    * other representations for character sequences, such as external
    * files.
    * - The controlled sequences can support operations @e directly to or
    * from associated sequences.
    * - The controlled sequences can impose limitations on how the
    * program can read characters from a sequence, write characters to
    * a sequence, put characters back into an input sequence, or alter
    * the stream position.
    * .
    But the code compiles and runs as expected.
    Isn't cout's streambuf being written on in the example ?
    Or..more likely...what punchline am I missing ?
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    2,421
    Quote Originally Posted by streambuf
    * -# Stream buffers can impose various constraints on the sequences
    * they control. Some constraints are:
    * - The controlled input sequence can be not readable.
    * - The controlled output sequence can be not writable. <------------- [THIS is the line I'm talking about]
    * - The controlled sequences can be associated with the contents of
    * other representations for character sequences, such as external
    * files.
    * - The controlled sequences can support operations @e directly to or
    * from associated sequences.
    * - The controlled sequences can impose limitations on how the
    * program can read characters from a sequence, write characters to
    * a sequence, put characters back into an input sequence, or alter
    * the stream position.
    * .
    I think the truly operative phrase here is "Stream buffers can impose various constraints on the sequences they control."

    it seems to me that the ones they list are a few of the options available, and that not all of them are present in every instance of a streambuf.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,307
    Elkvis nailed it.

    The word "can" means "able to" which, because it is not mandatory, is distinct from the meaning of "shall" which means "has to".

    In some legal contracts, the word "shall" is used to state essential (non-negotiable) requirements, whereas "can" is used to state that something is desirable (nice to have, but negotiable)
    Right 98% of the time, and don't care about the other 3%.

  4. #4
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by Elkvis
    ....and that not all of them are present in every instance of a streambuf.....
    Quote Originally Posted by grumpy
    .....whereas "can" is used to state that something is desirable (nice to have, but negotiable)....
    Wouldn't that make using streambuf `s(and its children) very non portable ?
    ..if .. say the runtime library stops allowing something which a piece of code relied upon...
    or if the code is compiled with a different compiler ?
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,307
    It can affect portability, yes.

    The trick is to understand what can be relied on and what cannot. Using multiple compilers (and running your tests with each) can help with that.

    Bear in mind that the quoted information is not from the standard. It is presumably a view of one library vendor about some qualities that may be acceptable.
    Right 98% of the time, and don't care about the other 3%.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 39
    Last Post: 01-18-2009, 10:53 PM
  2. I don't understand what is wrong...
    By flaran in forum C++ Programming
    Replies: 4
    Last Post: 01-18-2006, 05:46 AM
  3. Can't understand what I'm doing wrong.
    By agentxx04 in forum C Programming
    Replies: 11
    Last Post: 10-22-2004, 07:53 PM
  4. help......i dont understand what i am doing wrong?
    By Grifftt in forum C Programming
    Replies: 2
    Last Post: 10-18-2002, 11:37 PM
  5. I don't understand what i'm doing wrong..
    By knutso in forum C Programming
    Replies: 4
    Last Post: 03-15-2002, 06:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21