0

with the following code:

int foo = bar[1].toInt;

or

int foo = bar[1].toInt();

I get this error

request for member 'toInt' in '*(bar + 1u)', which is of non-class type 'uint8_t {aka unsigned char}'

the context for this is bar is the response from a HTTP client over web sockets

8
2

The Arduino function toInt requires a String object. You're passing it a single character, not a String.

int foo = String(bar[1]).toInt();
1

I'm not quite clean on what you are trying to do. So lets assume the String has "abc123" in and you want the numeric part.

const String input = "abc123";
const int foo = input.toInt();  // This will not work!    

const String input = "abc123";
const String tmp = input.substring(3); // Take the end of the string
const int foo = input.toInt();  // foo == 123

const String input = "abc123";
const String tmp = input.substring(3,4); // Take the end of the string
const int foo = input.toInt();  // foo == 1 or 12 (can't quite tell from the docs)

Is one of those what you want to do?

You can't take a character and then apply a function from the string class to it without making it a String first.

int foo = String(bar[1]).toInt();  // This should work
2
  • You mean .toInt()? Mar 13 '17 at 13:23
  • I thought I did then I read the original question again. I don't know about these new fangled String classes. If its not a uchar I don't use it :) Corrected post. Mar 13 '17 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.