Ask Your Question
0

How can I save stringstream data into a struct member and then print it using Serial.println() in the Arduino ESP32 framework?

asked 2022-06-10 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-05-03 09:00:00 +0000

qstack gravatar image

You can save stringstream data into a struct member using the << operator, just like you would with a regular stringstream. Here's an example:

struct MyStruct {
  std::stringstream data;
};

MyStruct myStruct;

myStruct.data << "Hello, world!\n";

Serial.println(myStruct.data.str().c_str());

In this example, we define a struct called MyStruct that has a data member that is a stringstream. We then create an instance of this struct called myStruct.

We then use the << operator to insert the string "Hello, world!\n" into the data member of myStruct. Note that we're using the c_str() function to convert the stringstream to a const char* that we can pass to Serial.println().

Finally, we call Serial.println() to print the contents of the data member of myStruct.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-06-10 11:00:00 +0000

Seen: 7 times

Last updated: May 03 '21