Why isn't atoi() working for me?
Mar 21, 2012 at 5:01am UTC
instructionRegister is a private member string variable in my Simpletron class.
It will always look something like this: +21007
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void Simpletron::decode()
{
string operandTemp;
string opCodeTemp;
opCodeTemp[0] = instructionRegister[1];
opCodeTemp[1] = instructionRegister[2];
operandTemp[0] = instructionRegister[3];
operandTemp[1] = instructionRegister[4];
operandTemp[2] = instructionRegister[5];
operationCode = atoi(opCodeTemp);
operand = atoi(operandTemp);
}
Error message reads: simpletron.cpp(29) : error C2664: 'atoi' : cannot convert parameter 1 from 'std::string' to 'const char *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Anyone know why?
~James
Mar 21, 2012 at 5:05am UTC
Make this changes. As atoi is expecting "const char*" type and you have given string type.
1 2
operationCode = atoi(opCodeTemp.c_str());
operand = atoi(operandTemp.c_str());
Mar 21, 2012 at 5:17am UTC
And what type are variables operationCode and operand?
Topic archived. No new replies allowed.