Typecasting - (Integer to String)

This is a discussion on Typecasting - (Integer to String) within the C++ Programming forums, part of the General Programming Boards category; I am trying to figure out how to convert a integer to a string. I've been told there is a ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    2

    Talking Typecasting - (Integer to String)

    I am trying to figure out how to convert a integer to a string. I've been told there is a function to do this. If anyone can help that would be great.

    Thanks
    Shane

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    There are several ways to convert an integer to a string. One common C++ way to do it is using stringstreams:
    Code:
    #include <iostream>
    #include <string>
    #include <sstream>
    
    int main()
    {
        int i = 10;
        std::ostringstream theStream;
        theStream << i << " + " << 5 << " = " << i+5;
        std::string theString = theStream.str();
        std::cout << theString << std::endl;
    }

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    2

    Thumbs up Follow-up

    Thanks alot for the help!!! I will let you know how it works out.

    Thanks
    Shane

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  3. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 02:40 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  5. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 10:32 AM

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