Open GoogleCodeExporter opened 9 years ago
[Apologies for the initial report - trying again...!]
Even though the implementation of String.toCharArray() and String.getBytes()
return a copy of the internal buffer they are non-const, which means that
rather than being able to write code such as:
const String s("A string");
char charArray[9];
s.toCharArray(charArray, 9);
You have to cast away the const-ness (which is a bit messy):
const String s("A string");
char charArray[9];
((String)s).toCharArray(charArray, 9);
Both functions could be made const without breaking existing calling code and
simplifying usage in this scenario.
Original comment by matthew....@gmail.com
on 3 Jun 2011 at 10:01
I see that this change has already gone into the 1.0 new-extension branch as a
result of the String class changes.
Original comment by matthew....@gmail.com
on 7 Jun 2011 at 9:03
I know it's been a while.. perhaps you remember this?
did you ever get the string to work?
see error in comment
Thank you!
my code:
//from SerialEvent
const String g("geiger");
String inputString = "g"; // a string to hold incoming data
char charArray[80];
((String)g).toCharArray(charArray, 80); // error: expected constructor, destructor, or type conversion before 'g'
boolean stringComplete = false; // whether the string is complete
void setup()
{
delay(1000);
Ethernet.begin(mac, ip);
// Ethernet.begin(mac);
Serial.begin(9600);
// String::toCharArray() //testing
inputString.reserve(200); //(200
// inputString.toCharArray(g, 80);
if (twitter.post(charArray))
{
Original comment by rmacar...@gmail.com
on 24 Apr 2012 at 4:45
This has been fixed in Arduino 1.0.
Original comment by matthew....@gmail.com
on 24 Apr 2012 at 8:12
Thank you!
how has it been fixed?
((String)g).toCharArray(charArray, 80)
gives errors no matter how i phrase it
Original comment by rmacar...@gmail.com
on 24 Apr 2012 at 8:36
Original issue reported on code.google.com by
matthew....@gmail.com
on 3 Jun 2011 at 9:54