Unbelievably Silly

From: R.N. Smith (mia01_at_keele.ac.uk)
Date: 10/31/03


Date: Fri, 31 Oct 2003 15:11:16 -0000

The following program, compiled with the GNU C++ compiler (actually g++)
fails to work.

Enter an integer and waits until a letter has been typed in. It then outputs
only the first digit of the integer read.

e.g. if we enter

1234 <return>
c<return>

the prog responds :-

number is 1

How can anything this simple go wrong ?

Rob

#include <iostream.h>
using namespace std;

int main()
{
  int i;
  cin>>i;
  cout << "number is " << i <<endl;
  return(0);
}



Relevant Pages

  • Re: Linking a MySQL client
    ... > I'm trying to add MySQL client functionality to a project but I'm having ... > To compile this program using the GNU C compiler, ... > int mysqlifQuery ... By default GNU Make ...
    (comp.os.linux.development.apps)
  • Re: It Pays to Enrich Your C Skills
    ... Check if you can score a perfect 10 (without using a compiler). ... int main{ ... struct bitfield { ... out if it is a negative integer constant or a constant expression ...
    (comp.lang.c.moderated)
  • OT: Re: Perl Peeves
    ... I see the result of a test being used as an int. ... the compiler just assumed you knew what you were doing ... introduced to the language later, so void * was unheard of in most code. ... This didn't mean bool was special, declaring it just signaled to the ...
    (comp.lang.perl.misc)
  • Re: OT: Re: Perl Peeves
    ... when I see the result of a test being used as an int. ... compiler just assumed you knew what you were doing and would ... This didn't mean bool was special, declaring it just signaled to the ... What "normalization of bool results is built into the compiler"? ...
    (comp.lang.perl.misc)
  • Re: [CodeGallery] MFC MD5 Calculator
    ... Then when they added types, internally, the compiler still thought they were int values, ... ANSI standard began to emerge that the language design ...
    (microsoft.public.vc.mfc)