Error: 'itoa has not been declared in this area

I get the following error:
prog.cpp: In the member function 'void Sequence :: GetSequence ():
prog.cpp: 45: error:' itoa was not declared in this area

I have a cstdlib header file, but it does not work.

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

template<typename T>
struct predicate :
public binary_function<T, T, bool>
{
    bool operator() (const T& l,const T &r) const
    {
          return l < r;
    }
};

class Sequence
{
    public:
    Sequence(vector<string> &v)
    { /* trimmed */ }

void GetSequence(void)
{
    string indices = "";
    char buf[16];

    for( map<int, string>::iterator
            i = m.begin(); i != m.end(); ++i )
    {
indices = indices
                  + string(itoa((i->first), buf, 10));
    }

    SortedSequence("", indices);
}

// --- trimmed ---
+5
source share
3 answers

Not in the standard itoa, but in C ++ 11 you can use the std :: to_string functions .

+12
source

In C ++ 11 you can use std::to_string. If this is not available to you, you can use std::stringstream:

std::stringstream ss; int x = 23;
ss << x;
std::string str = ss.str();

, boost:: lexical_cast. lexical_cast std::stringstream, , .

- Boost.Karma, . .

itoa - . C, ++. , , , , , .

+6

, itoa MinGW GCC 4.9.3, , MinGW-w64 GCC 5.3.0.

, vswprintf, std::stoi std::to_string MinGW.

0
source

All Articles