The error occurs when I try to use the atoi(const char*) function in the following line…
externalEncryptionRawHolder[u] = atoi(parser.next());
The ‘parser’ object is a string parser and the ‘next’ method returns a string. I think the error has something to do with the fact that the string within the ‘atoi’ function isn’t a constant… but I’m not sure. The gist of the error is ‘cannot convert string to const char *’. How can I make my string constant? Any help would be very appreciated (by the way, in case you’re wondering what the index ‘u’ is, this is within a ‘for’ loop).
You have to call
c_str()on thestringobject to get aconst char*:Note, though, that you should not do this:
Because
cwill point to the memory that was managed by thestringreturned byparser.next(), which gets destroyed at the end of the expression, so thencpoints to deallocated memory. The first example is ok though because the string is not destroyed until afteratoihas returned.