Converting Integer to string

This is a discussion on Converting Integer to string within the C++ Programming forums, part of the General Programming Boards category; I know atoi() converts a string to an integer, but how would I put an integer value into a string? ...

  1. #1
    rm3
    Guest

    Converting Integer to string

    I know atoi() converts a string to an integer, but how would I put an integer value into a string?
    Also, how do I completely clear out a string w/out deleting it?

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    66
    I believe there is also a itoa (integer to alpha numeric). What do you mean clear out string without deleting?? Or if you just wanna put an integer at the end of string use strcat() adds a string to the end of a string.



    Ryan

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Another option is sprintf() is <stdio.h>

    char str[31];
    int num = 1111;

    sprintf(str,"%d",num);
    cout << "str:" << str << endl;

    Also to clear a string:
    strcpy(str,"");

Popular pages Recent additions subscribe to a feed

Similar Threads

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

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