cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CUBEIDE C++ Question - There doesn't appear to be a IDE specific question area.

NW27
Associate III

I have tried making a Project from scratch and selecting the C++ during the wizard, and also tried converting an existing project by going to properties and selecting convert to C++.

It just doesn't seem to be a C++ project.

I'm using a STM32L476RG dev board and select this board in the wizard process. I select the C++ option but none of the produced files have a CPP extension, including the main.c.

If I put the following in the main.c file:

#include <string> // I do not get an error on this line but...

string fred = "Fred"; // produces an error (or two)

../Core/Src/main.cpp:32:1: error: 'string' does not name a type; did you mean 'stdin'?

 string fred = "Fred";

 ^~~~~~

Is this the correct way of generating a C++ project?

Does the main file need to be main.c or main.cpp?

Is there anything else I need to change?

Thanks,

Neil

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Change string to std::string or use "using namespace std". Possibly string isn't put in the global namespace by default.

If you want C++, the file needs to be "*.cpp", as you did. STM32CubeIDE doesn't have good C++ support as of now.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

Change string to std::string or use "using namespace std". Possibly string isn't put in the global namespace by default.

If you want C++, the file needs to be "*.cpp", as you did. STM32CubeIDE doesn't have good C++ support as of now.

If you feel a post has answered your question, please click "Accept as Solution".
NW27
Associate III

Great thanks.