Stringstream bug with mbed-os-6

Hello,

I’m familiar with using stringstreams to format my serial or tcp communications.

But since mbed-os-6 I have a problem with inserting numbers parameters to the stream.

Example with mbed-os-5.15.3 work fine

#include "mbed.h"
#include <sstream>

Serial pc(USBTX, USBRX, 115200);

int main(void)
{
stringstream sstream;
sstream << "\nMbed OS " << MBED_VERSION;
pc.printf("%s", sstream.str().c_str());
}

Answer: Mbed OS 51503

Example with mbed-os-6.0.0 don’t work

#include "mbed.h"
#include <sstream>

UnbufferedSerial pc(USBTX, USBRX, 115200);

int main(void)
{
stringstream sstream;
sstream << "\nMbed OS " << MBED_VERSION;
pc.write(sstream.str().c_str(), sstream.str().size());
}

Answer: Mbed OS

I tried it with online compiler and mbed studio is the same thing.

Does anyone have any ideas on how to solve this problem?

Thank you,
YSI

Hi YSI,
please check this post from Kentaro Okuda .
So try to add into the mbed_app.json

{
	"target_overrides": {
	    "*": {
	        "target.printf_lib": "std"
	    }
	}
}

BR, Jan

Thank you Jan it works.

The releases note indicates minimal-printf is set by default with mbed-os-6.0 but does not indicate that it can be a breaking change.

Next time I’ll take “If your application requires more advanced functionality you’ll have to revert to using standard library version.” for a breaking change.

Thanks again Jan!