Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Development & Programming > Programming Talk
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Programming Talk
This forum is for all programming questions.
The questions do not have to be directly related to Ubuntu and any programming language is allowed.

 
Thread Tools Display Modes
Old October 5th, 2006   #1
thenetduck
Dipped in Ubuntu
 
thenetduck's Avatar
 
Join Date: Sep 2006
Beans: 529
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);
thenetduck is offline   Reply With Quote
Old October 5th, 2006   #2
thumper
Dipped in Ubuntu
 
thumper's Avatar
 
Join Date: Mar 2005
Location: Dunedin, NZ
Beans: 562
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
thumper is offline   Reply With Quote
Old October 5th, 2006   #3
thumper
Dipped in Ubuntu
 
thumper's Avatar
 
Join Date: Mar 2005
Location: Dunedin, NZ
Beans: 562
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
thumper is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:57 PM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. lingonberry