![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
|
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 |
|
|
#1 |
|
Dipped in Ubuntu
![]() 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);
|
|
|
|
|
|
#2 |
|
Dipped in Ubuntu
![]() 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);
// ...
}
Code:
#include <sstream>
void convert(int number)
{
std::istringstream sin;
sin << number;
std::string val = sin.str();
// ...
}
__________________
ACCU - for programmers who care |
|
|
|
|
|
#3 |
|
Dipped in Ubuntu
![]() 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();
// ...
}
__________________
ACCU - for programmers who care |
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|