Skip to main content
NW27
Associate II
June 1, 2020
Solved

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

  • June 1, 2020
  • 2 replies
  • 1905 views

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

This topic has been closed for replies.
Best answer by TDK

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.

2 replies

TDK
TDKAnswer
Super User
June 1, 2020

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
NW27Author
Associate II
June 1, 2020

Great thanks.