Hello @AnYufan ,
First let me thank you for posting and welcome to the ST Community.
I suggest that you take a look at this Post.
It highlights some of the points to bear in mind while programming an STM32 microcontroller using C++ on STM32CubeIDE.
Thanks.
Mahmoud