Is input/output stream buffer behaviour random acc. to C++ standard?

Discussion in 'C++' started by qazmlp1209@rediffmail.com, May 29, 2005.

  1. Guest

    FAQ at
    "http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.6"
    states that the following program will not work properly:
    ---------------
    int main()
    {
    char name[1000];
    int age;

    for (;;)
    {
    std::cout<< "Name: ";
    std::cin >> name;
    std::cout<< "Age: ";
    std::cin >> age;
    }
    }
    ---------------

    But,if I run the above program on my machine, it works without any
    problems. So, does it mean that, keeping the 'non-digit character
    within buffer' problem is a random behaviour exhibited by some/all
    systems? I could understand that, 'ignore()' of non-digit characters
    that are left behind, is safer. But, I would like to know what exactly
    is the case without that.
     
    , May 29, 2005
    #1
    1. Advertising

  2. wrote:
    > FAQ at
    > "http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.6"
    > states that the following program will not work properly:
    > ---------------
    > int main()
    > {
    > char name[1000];
    > int age;
    >
    > for (;;)
    > {
    > std::cout<< "Name: ";
    > std::cin >> name;
    > std::cout<< "Age: ";
    > std::cin >> age;
    > }
    > }
    > ---------------
    >
    > But,if I run the above program on my machine, it works without any
    > problems.


    What input are you giving it?

    > So, does it mean that, keeping the 'non-digit character
    > within buffer' problem is a random behaviour exhibited by some/all
    > systems?


    No.

    > I could understand that, 'ignore()' of non-digit characters
    > that are left behind, is safer. But, I would like to know what exactly
    > is the case without that.


    Try giving it some garbage instead of an integer when 'age' is requested.

    V
     
    Victor Bazarov, May 29, 2005
    #2
    1. Advertising

  3. wrote:
    > FAQ at
    > "http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.6"
    > states that the following program will not work properly:
    > ---------------
    > int main()
    > {
    > char name[1000];
    > int age;
    >
    > for (;;)
    > {
    > std::cout<< "Name: ";
    > std::cin >> name;
    > std::cout<< "Age: ";
    > std::cin >> age;
    > }
    > }
    > ---------------
    >
    > But,if I run the above program on my machine, it works without any
    > problems. So, does it mean that, keeping the 'non-digit character
    > within buffer' problem is a random behaviour exhibited by some/all
    > systems? I could understand that, 'ignore()' of non-digit characters
    > that are left behind, is safer. But, I would like to know what exactly
    > is the case without that.
    >


    Does it work correctly when you enter "abc" or "9 xx" in response
    to the "Age:" prompt?

    Regards,
    Larry
     
    Larry I Smith, May 29, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kashif Ur Rehman
    Replies:
    2
    Views:
    868
    Tom Hawtin
    May 17, 2007
  2. globalrev
    Replies:
    4
    Views:
    774
    Gabriel Genellina
    Apr 20, 2008
  3. Tomás Ó hÉilidhe

    Standard input stream behaviour on Linux

    Tomás Ó hÉilidhe, Oct 22, 2008, in forum: C Programming
    Replies:
    23
    Views:
    1,107
    John Bode
    Oct 23, 2008
  4. Alex Vinokur
    Replies:
    2
    Views:
    287
    Alex Vinokur
    Dec 19, 2012
  5. Roedy Green

    byte stream vs char stream buffer

    Roedy Green, May 7, 2014, in forum: Java
    Replies:
    20
    Views:
    205
    Silvio
    May 18, 2014
Loading...

Share This Page