The Arduino String implementation will do the logical thing. You can always check the source if you wonder what it's up to.
This means that it's malloc happy, like most any string implementation. Given the 328's minimal RAM, I'm not a big fan of string processing on the Arduino. I think it's better to leave that to a PC. Or an Arduino Mega.
C++ is a superset of C. What you would have done in C is what you still need to do in C++.
Just as a point of reference, structs are typically used to hold data. Classes are used to hold data and methods. Most of what you are doing, Beakie, involves classes, not structs.
While what you are doing CAN be done with structs, the implementations really look like classes, so you should be using classes.
Classes offer the advantage in that you can have public and private data and methods.
I think if one is about to add methods to a struct (some kind of Frankenstein IMHO) then he'd better invest a little time in learning how to create proper classes and stick with that. For simple cases (ignoring inheritance and virtual methods) it's not much more than syntax.
In C++, struct and class are exactly the same thing, except that a struct's members are public by default. There can be times when it's useful to have convenience methods for structs, just realize that it's not providing data hiding. A reasonable example is a datetime structure. There's value in having public data in that case, but you might want to have a "convert to unix time" method, and making it a struct method would be logical.
C++ is a superset of C. What you would have done in C is what you still need to do in C++.
I think there is a subtlety in this question. In C, one would not have a "string class", so I believe the OP meant, "When I work with strings in C", meaning "using char*". So there is a big difference of course between using char*'s and the Arduino String class, and I think that's what the question was after.
I think if one is about to add methods to a struct (some kind of Frankenstein IMHO)
What's "Frankenstein" (it's pronounced "Fraawkun-shteen") about it?
Structs can have ctors/dtors, can be derived from other structs...
As has been pointed out, their members are public, by default, that's all.
If you want 'em private, make 'em private.
Go on - rock the boat a little!
If one wants to use structs like full-blown objects, then why not use the proper syntax and write a class ? Adding a method to a struct might be handy sometimes, but as PaulS wrote before:
Just as a point of reference, structs are typically used to hold data. Classes are used to hold data and methods
But hey, at the end of the day nothing stops you from using the tool you feel most comfortable with, even if it's not the recommended one for that particular job.
@mromani:
I think you're missing the point; structs were what we used for methods and data in C, before C++ introduced the class.
It isn't a question of using the wrong tool, it is just a left-handed version of the same tool.
Presumably the only reason Stroustrup didn't carry over the struct as the mechanism of choice was that he wanted to introduce the concept of private and public for encapsulation purposes (i.e. sound software engineering).
Making struct members private by default would have broken a lot of existing programs.
That's the point: C++ structs-with-methds are a refinment of a leftover from the old C days.
Now that we have proper classes, I don't see the point in using them anymore, except for very specific use cases.
As I said, that's just MHO.
mromani:
I don't see the point in using them anymore, except for very specific use cases.
Stroustrup himself uses a similar example to mine above in his CSci class
// simple Date
// guarantee initialization with constructor
// provide some notational convenience
struct Date {
int y,m,d; // year, month, day
Date(int y, int m, int d); // constructor: check for valid date and initialize
void add_day(int n); // increase the Date by n days
};