Print on serial with mbed

Hello I am new to the mbed os
I have been trying to print on serial
I tried using this code which I found on one the forums here :

#include <mbed.h>
#include “SerialStream.h”

BufferedSerial serial(USBTX, USBRX, 115200);
FILE * pc;

int main() {
pc = fdopen(&serial, “r+”);

    fprintf(pc, "Hello world!\n");


but I get this error Identifier “nulptr” is undentified serial stream(serialclass_&_serialclass , const char*name =nullptr)"
is there something I can do here to fix this code or is there any other way to print on serial


The source seems to be from here - SerialStream - Bringing MBed serial ports back like it’s 1999…… | Mbed, but I cannot reproduce your issue - tested with Nucleo-F767ZI, MbedOS 6.15.1 under KeilStudio.
However, the error probably comes from constructor of SerialStream, which is not used in this code, so try to run CleanBuild, and the #include "SerialStream.h" in the context of this code is also pointless.

BR, Jan

hello John,

thank you for your reply , at first I was compiling with mbed online compiler but I tried it with the online KeilStudio like you and it worked ,and i used putty serial and started printing messages yeahh