converting a integer to a string

This is a discussion on converting a integer to a string within the C++ Programming forums, part of the General Programming Boards category; Is there a function that will convert a integer into a string? I tried typecasting, and that didn't work. I ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    3

    converting a integer to a string

    Is there a function that will convert a integer into a string? I tried typecasting, and that didn't work. I also tried itoa, which also gave me errors.

    Thanks.

  2. #2
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    Posts
    149
    I always prefer the old C style method:
    Code:
    #include <stdlib.h>
    
    int main()
    {
        int Number = 347;
        char NumberString[10] = "";
    
        sprintf(NumberString, "%d", Number);
        return 0;
    }
    David
    One Ring to rule them all, One Ring to find them,
    One Ring to bring them all and in the darkness bind them
    In the Land of Mordor where the Shadows lie.

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    I always use sprintf() as well, but itoa() should be mentioned - look at it in the help.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  5. Converting a string to an integer
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 08-31-2001, 10:01 PM

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