How can I read one number at a time?

This is a discussion on How can I read one number at a time? within the C++ Programming forums, part of the General Programming Boards category; How can I read in one number at a time from a string of numbers? Something like this: 1429943983... I ...

  1. #1
    Registered User Bad_Scooter's Avatar
    Join Date
    Mar 2003
    Posts
    15

    How can I read one number at a time?

    How can I read in one number at a time from a string of numbers?
    Something like this:

    1429943983...

    I want to read in the one, then the four, and so on. My first thought was to use get. Something like fin.get(number); But this statement only seems to accept a char, not an int. I am at a loss, short of reading in a char and converting to an int through 10 if statements. Any help would be great.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Do that. Read a character, convert it to a number. Subtract the character value of zero from the character number to get its numeric value. Example:

    cout << "'4' - '0' = " << '4' - '0' << endl;

    Enjoy.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User Bad_Scooter's Avatar
    Join Date
    Mar 2003
    Posts
    15
    Thanks, that's what I'll do, I just thought there may have been an easier way.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read until negative number
    By m_user in forum C Programming
    Replies: 10
    Last Post: 04-03-2009, 06:38 AM
  2. Number Guessing
    By blacknapalm in forum C Programming
    Replies: 2
    Last Post: 10-01-2008, 01:48 AM
  3. Read and set\change system time
    By Hexxx in forum C++ Programming
    Replies: 9
    Last Post: 01-02-2006, 06:11 AM
  4. how to read hard disk serial number
    By toufiq_raja in forum C Programming
    Replies: 4
    Last Post: 08-18-2005, 10:08 PM
  5. Replies: 3
    Last Post: 03-04-2005, 01:46 PM

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