I want to do something similar to this:
char* a = (char*)msg[0];
char* b = (char*)msg[1];
char* c = a + "," + b;
Where msg
is an array of int
.
N.B.: This is Arduino C++, not regular C++.
I want to do something similar to this:
char* a = (char*)msg[0];
char* b = (char*)msg[1];
char* c = a + "," + b;
Where msg
is an array of int
.
N.B.: This is Arduino C++, not regular C++.
Arduino doesn't use std::string
, instead it uses String
(note the capital S and dropped std::
). They're used the same way as std::string
for the most part. So basically you should just be able to do this:
String a("hello");
String b(" world");
c = a + b;
If you want to convert an integer to a String
, it has a constructor to do just that, e.g.:
String a = String(msg[0]);
String b = String(msg[1]);
See strcat. You seem to be programming C, not C++. This should be covered in the most basic tutorials.
SOLUTION
so here is my solution thank everyone.
String a = String(msg[0]);
String b = String(msg[1]);
String c = a + "," + b;
char* d;
c.toCharArray(d,c.length());
mclient.publish("topic1/sensorAck",d);