Results 1 to 3 of 3

Thread: I get an "itoa was not declared in the scope"

  1. #1
    Join Date
    Sep 2006
    Beans
    530

    I get an "itoa was not declared in the scope"

    hey
    I am trying to convert an int to a string. I'm trying to use the itoa() fucntion but its not working. it gives me the error in the title. Does anyone know what causese this?
    Thanks,
    The Net Duck

    btw its in c++

    Code:
    string convertToRoman (int number)
    {
       // Initialized
       string sNumber;
       itoa(number, sNumber, 10);

  2. #2
    Join Date
    Mar 2005
    Location
    Dunedin, NZ
    Beans
    559
    Distro
    Kubuntu 7.10 Gutsy Gibbon

    Re: I get an "itoa was not declared in the scope"

    For C++ avoid using itoa. Preference is to use boost, or failing that, a stringstream.

    Code:
    #include <boost/lexical_cast.hpp>
    
    void convert(int number)
    {
       std::string val = boost::lexical_cast<std::string>(number);
       // ...
    }
    or

    Code:
    #include <sstream>
    
    void convert(int number)
    {
       std::istringstream sin;
       sin << number;
       std::string val = sin.str();
       // ...
    }
    ACCU - for programmers who care

  3. #3
    Join Date
    Mar 2005
    Location
    Dunedin, NZ
    Beans
    559
    Distro
    Kubuntu 7.10 Gutsy Gibbon

    Re: I get an "itoa was not declared in the scope"

    As was noted in another post, I got this the wrong way around.

    You want an ostringstream not an istringstream.

    Code:
    #include <sstream>
    
    void convert(int number)
    {
       std::ostringstream sin;
       sin << number;
       std::string val = sin.str();
       // ...
    }
    *blush*
    ACCU - for programmers who care

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •