How to convert an integer into a string

Discussion in 'C++' started by silverburgh.meryl@gmail.com, Feb 1, 2006.

  1. Guest

    In my c++ code, I try to call "itoa"

    #include <stdio.h>
    #include <stdlib.h>

    int index2
    char buffer [4];
    ::itoa (index2,buffer,10);

    but I get this compile error:

    Context.cpp:2304: error: '::itoa' has not been declared

    Can you please tell me how to fix that?

    Thank you.
     
    , Feb 1, 2006
    #1
    1. Advertising

  2. Guest

    i think its "_itoa()", isn't it?
     
    , Feb 1, 2006
    #2
    1. Advertising

  3. Gavin Deane Guest

    wrote:
    > In my c++ code, I try to call "itoa"
    >
    > #include <stdio.h>
    > #include <stdlib.h>
    >
    > int index2
    > char buffer [4];
    > ::itoa (index2,buffer,10);
    >
    > but I get this compile error:
    >
    > Context.cpp:2304: error: '::itoa' has not been declared
    >
    > Can you please tell me how to fix that?
    >
    > Thank you.


    There is no such function as itoa in standard C++.

    http://www.parashift.com/c -faq-lite/misc-technical-issues.html#faq-39.1

    Gavin Deane
     
    Gavin Deane, Feb 1, 2006
    #3
  4. Guest

  5. Gavin Deane Guest

    Gavin Deane, Feb 1, 2006
    #5
  6. Guest

    I would like to do this on Linux, with G++. I think this question is
    on-topic in this newsgroup.

    Thanks for any help.
     
    , Feb 1, 2006
    #6
  7. Gavin Deane Guest

    wrote:
    > I would like to do this on Linux, with G++. I think this question is
    > on-topic in this newsgroup.
    >
    > Thanks for any help.


    The question is on-topic and I posted a link to the FAQ which shows you
    what you want. Here it is again.

    http://www.parashift.com/c -faq-lite/misc-technical-issues.html#faq-39.1

    The use of itoa was the off-topic bit.

    HTH
    Gavin Deane
     
    Gavin Deane, Feb 1, 2006
    #7
  8. Geo Guest

    wrote:
    > I would like to do this on Linux, with G++. I think this question is
    > on-topic in this newsgroup.
    >
    > Thanks for any help.


    int i = 1234;
    std::stringstream ss;
    ss << i;
    std::string str(ss.str());
     
    Geo, Feb 1, 2006
    #8
  9. escreveu:

    > i think its "_itoa()", isn't it?


    According to the Standard (17.4.3.1.2):

    "Each name that begins with an underscore is reserved to the
    implementation for use as a name in the global namespace."

    Thus this name (_itoa) is reserved to the implementation and as such is
    implementation specific, and off-topic.

    HTH,

    Marcelo Pinto.
     
    Marcelo Pinto, Feb 1, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Azmie
    Replies:
    12
    Views:
    1,066,967
    Azmie
    Dec 30, 2003
  2. Replies:
    2
    Views:
    1,317
    Ravi Teja
    Jan 22, 2007
  3. priyanka
    Replies:
    3
    Views:
    1,345
    Thomas J. Gritzan
    Jul 18, 2006
  4. news
    Replies:
    2
    Views:
    1,112
  5. Randy Kramer
    Replies:
    12
    Views:
    377
    Robert Klemme
    Oct 25, 2007
Loading...

Share This Page