quick casting question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • schmals
    New Member
    • Oct 2007
    • 8

    quick casting question

    Hey, I have sort of a quick question. I have a string that is comprised of numerical values. I am lobbing off each number from the string and placing it in another array comprised of integers. How can I convert the character value from the string into the actual numerical value?

    Thanks!
  • mattmao
    New Member
    • Aug 2007
    • 121

    #2
    Hi.

    Use the atol method in the stdlib.h:

    http://www.cplusplus.c om/reference/clibrary/cstdlib/atol.html

    This page tells you how.

    Comment

    • schmals
      New Member
      • Oct 2007
      • 8

      #3
      ah, nice.. thank you

      Comment

      • oler1s
        Recognized Expert Contributor
        • Aug 2007
        • 671

        #4
        Question, are you using C or C++? strtol or strtod would be the function to use in C. In C++, a more preferable method may be with stringstreams.

        Also, based on the title of your question (casting), I'm betting you tried to cast a string as an integer and found it to fail miserably. Remember that casting does not do any logic. It's a method of treating a variable type as another, and if you don't understand the low level implications, you are in for a world of surprise.

        Comment

        Working...