Domanda

This may be a vaugue question but im getting this error

Simulator.cpp: In member function `void Simulator::generatePassengers()': 
Simulator.cpp:60: error: `itoa' undeclared (first use this function) 

This is the code im having an issue with

itoa(i,buf,10);

What can i use to fix this issue because on one compiler i get this issue on another i dont. So im stumped here has to work on both.

    char buf[3];
    if(i<10)
    {
        key1.append("0");
        key2.append("0");
        key3.append("0");
    }
    itoa(i,buf,10);
    key1.append(buf);
    key2.append(buf);
    key3.append(buf);
È stato utile?

Soluzione 2

Does this work?

#include <string>
std::string buf = std::to_string(i);
key1.append(buf);
key2.append(buf);
key3.append(buf);

Altri suggerimenti

Your platform doesn't have itoa. It's not specified by any standard. You can use any replacement you like, including printf or just writing your own.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top