我的问题是我不知道如何将 int value 转换为 char array char* m_value
。我尝试使用 itoa 但它不起作用。itoa(m_val, m_wartosc, 10);
也许还有其他功能可以做到这一点?
主文件
int main(int argc, char *argv[])
{
LargeNumber l1;
LargeNumber l3(172839); //how to convert this int to char*
return 0;
}
大数.h
class LargeNumber{
public:
LargeNumber()
{
m_array = "0"; //zero for no arg.
}
LargeNumber(int val):m_val(val)
{
itoa(m_val, m_array, 10); //doesn't work
//sprintf(m_array, "%d", m_val);
}
LargeNumber(const LargeNumber& p):m_array(p.m_array)
{ } //copy constructor
~LargeNumber(){
delete []m_array; //for object with new
}
public: //should be private
int m_val;
char* m_array;
};