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

  1. #1
    Registered User
    Join Date
    Oct 2006

    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?


  2. #2
    Registered User
    Join Date
    Oct 2004
    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
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Or you could read up on locale
    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.

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, 03: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