Converting Variables

This is a discussion on Converting Variables within the C++ Programming forums, part of the General Programming Boards category; I was just wondering, what would be the best way of converting a char variable (made up of numbers only, ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    21

    Converting Variables

    I was just wondering, what would be the best way of converting a char variable (made up of numbers only, up to three digits) into an int variable. Help appreiciated

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    A char variable can only hold a single digit. You probably mean a string (or a character array used to store a string).

    Use a stringstream (as in the first FAQ linked) or boost::lexical_cast.

  4. #4
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    This opposite to atoi. works nicely. I seem to reference this a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  3. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 10:07 PM
  4. Replies: 6
    Last Post: 01-02-2004, 12:01 PM
  5. functions to return 2 variables?
    By tim in forum C Programming
    Replies: 5
    Last Post: 02-18-2002, 01:39 PM

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