String class


Gets a pointer (const char *) to the internal c-string representation of the string. You can use this to pass to a function that require a c-string. This string cannot be modified.

const char *s = string.c_str();

const char * c_str() const;

The object also supports operator const char * so for things that specifically take a c-string (like Particle.publish) the conversion is automatic.

You would normally use c_str() if you need to pass the string to something like Serial.printlnf or where the conversion is ambiguous:"the string is: %s", string.c_str());

This is also helpful if you want to print out an IP address:"ip addr: %s", WiFi.localIP().toString().c_str());