Conversion from number to string or char* type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • niru132
    New Member
    • Jul 2007
    • 1

    Conversion from number to string or char* type

    how to convert a number into word using cpp
  • iWillLiveforever
    New Member
    • Feb 2007
    • 136

    #2
    wait do you mean an int into a char.

    if so check out atoi()

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      Next time, please read and follow the Posting Guidelines.

      Comment

      • ilikepython
        Recognized Expert Contributor
        • Feb 2007
        • 844

        #4
        Originally posted by iWillLiveforeve r
        wait do you mean an int into a char.

        if so check out atoi()
        Do you mean itoa()? Look at "atoi", ascii (string) to integer", "itoa" integer to ascii (string).

        You can also use a string stream:
        [code=cpp]
        #include <sstream>

        int num = 65;
        string numstr;

        stringstream ss;
        ss << num;
        ss >> numstr;

        cout << numstr << endl;
        [/code]

        Comment

        • iWillLiveforever
          New Member
          • Feb 2007
          • 136

          #5
          oops sorry I got confused between them I havent used them in a while.

          besides i usually do sprintf with a buffer to convert the two but most people find that way harder.

          Comment

          • iWillLiveforever
            New Member
            • Feb 2007
            • 136

            #6
            Originally posted by sicarie
            Next time, please read and follow the Posting Guidelines.
            To whom are you talking to niru132 or me?

            Comment

            • sicarie
              Recognized Expert Specialist
              • Nov 2006
              • 4677

              #7
              I was speaking to the OP. Its not a big deal this time, but it would have been easy for the OP to put that into Google and get the answer, or even this site as I know we have answered this question before. And with larger questions (once again why its not incredibly important in this case) its nice to have the code the OP used, or the methodology of how they are going about it.

              Edit:: I have changed the thread title to better describe the issue, and hopefully allow more people to either comment, or find an answer to a similar question (also in the Posting Guidelines ;)

              Comment

              Working...