Is it better to use c_str or toCharArray?
It seems like c_str() should be the preferred approach. Is there some reason why toCharArray() is more commonly used?


basically, I'd say it's a lack of knowledge from the people doing the codes you've seen. Definitely c_str() is better. Though, what I see even more often is the use of character arrays char* strings instead of String (and I plead guilty of that as well in my own codes).

And that's because the Arduino library has been built upon a messy set of C and C++ libraries and coding style. Trying to make things easier actually messed them up and complicated them more.

That's actually why we have new projects like xpcc trying to make a real and smart use of the C++ abilities in the embedded world.