Why does it read my '1,5' as a '1' ?

This is a discussion on Why does it read my '1,5' as a '1' ? within the C++ Programming forums, part of the General Programming Boards category; float a; cin >> a; cin.ignore(); When I do the stepover, and add a watch for my 'a', somethings mysterious ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    1

    Question Why does it read my '1,5' as a '1' ?

    float a;
    cin >> a; cin.ignore();

    When I do the stepover, and add a watch for my 'a', somethings mysterious happens:

    I punch in 1,5
    But in the watchlist it says: a=1

    I've tried with double and int too, but nothing works!

    Someone knows what I'm missing here?

    Carl

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    Regardless of how things work in Euro, in C++ decimal points are periods.
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Commas are kind of separators not decimal points as zx-1 already said.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,437
    Or you could read up on locale
    http://www.dinkumware.com/manuals/?m...ge=locale.html
    And set say LC_NUMERIC to something appropriate for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read() problems
    By yay4rei in forum C Programming
    Replies: 2
    Last Post: 07-21-2005, 10:47 AM
  2. How can I know the actual bytes read in a file read
    By pliang in forum C++ Programming
    Replies: 1
    Last Post: 06-08-2005, 04:23 PM
  3. What Would You Use To Read User Input?
    By djwicks in forum C Programming
    Replies: 11
    Last Post: 04-05-2005, 03:32 PM
  4. Read Array pro!!Plz help!!
    By Supra in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 02:49 PM
  5. Help! Can't read decimal number
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 09-07-2001, 02:09 AM

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