String class

c_str()

String::c_str, c_str, String.c_str

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.

// SYNTAX
const char *s = string.c_str();

// PROTOTYPE
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 Log.info where the conversion is ambiguous:

Log.info("the string is: %s", string.c_str());

This is also helpful if you want to print out an IP address:

Log.info("ip addr: %s", WiFi.localIP().toString().c_str());