How do you cast a string as an integer?

This is a discussion on How do you cast a string as an integer? within the C++ Programming forums, part of the General Programming Boards category; I have a number in a string (actually its a character array, c style string) and i want to put ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    22

    How do you cast a string as an integer?

    I have a number in a string (actually its a character array, c style string) and i want to put it in an integer variable. The character array simply contains one a digit in each index and then, of course, a terminating character (\0). I tried:

    integervariable = int(string);
    integervariable = (int)string;

    Niether of these works, they just put the ascii codes for the digits in there. How do i do it?

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,810
    integer = atoi(yourString);
    Woop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Conversion of character string to integer
    By supaben34 in forum C++ Programming
    Replies: 3
    Last Post: 10-30-2003, 04:34 AM
  5. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 11:32 AM

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