Skip to main content
MBany.1
Associate
November 7, 2020
Question

how to use a string (class) in ST32 Cpp code

  • November 7, 2020
  • 1 reply
  • 5189 views

hello everyone

I'm trying to use a string type (string class not char pointer or array) in my code

I have a lot of string messages in my program and a string class can help a lot

I see how arduino did it in their IDE, their string class is good, I think it should be possible to use it with ST32 MCUs,

I'm using Discovery (disco1) board with ST32CubeIDE.

This topic has been closed for replies.

1 reply

TDK
Super User
November 8, 2020

Convert your project to C++ (right click project -> Convert to C++), add a C++ source file, and use string within it:

#include <string>
 
std::string this_is_a_string = "Hello world!";

I verified this compiles but I did not test functionality.

You can also rename source files from *.c to *.cpp, but this can mess up global function references unless you do "extern "C"" to keep C linkage.

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