Thread: !cin

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    33

    !cin

    in this segment of code

    Code:
    loopCount = 1;
    while(true)
    {           cin>>num1;
                 if (!cin||num1>=100)
                         break;
                 cin??num2
                 if(!cin|| num2<=50)
                  break;
                cout<<sqrt(float(num1+num2)),,end1;
                loopcount++
    if(loopcount>10)
    break;
    why do they include !cin and what does it mean? does it just mean "not num1" or is cin different from num1??

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    cin>>num1;
    Here, you can enter several integers, separated by spaces. Only the first integer will be read though, but since the whole block is looping the rest of the numbers will also be read (in the next loops).
    Probably, cin returns 0 when there are no more numbers to read, thus exiting the loop.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    !cin will exit when a read error flag, or EOF, is detected. As Magos suggested, it appears that its primary purpose is to detect the EOF flag, but will exit if the data/file is corrupted in some way, as well.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cin problem
    By mikahell in forum C++ Programming
    Replies: 12
    Last Post: 08-22-2006, 11:14 AM
  2. Check if a cin is null
    By HumbuckeR in forum C++ Programming
    Replies: 6
    Last Post: 04-16-2006, 08:16 AM
  3. cin not allowing input after first use of function
    By Peter5897 in forum C++ Programming
    Replies: 5
    Last Post: 01-31-2006, 06:29 PM
  4. Overriding Cin with Cout
    By Tainted in forum C++ Programming
    Replies: 5
    Last Post: 10-06-2005, 02:57 PM
  5. multiple instances of cin
    By Chaplin27 in forum C++ Programming
    Replies: 4
    Last Post: 10-08-2004, 04:51 PM