I want to tuse the datatype STRING. But i can only do this when i include Arduino.h as a header (+ string.h).
Otherwise i get "'String' does not name a type". Is there another way without Arduino.h?
How to use strings in esp idf?
Re: How to use strings in esp idf?
These days, I am a big fan of writing ESP32 Apps in C++ as opposed to C. I still use the ESP-IDF (not Arduino libraries).
When writing apps in C++, one has access to all the APIs exposed by newlib and ESP-IDF but in addition, a new treasure chest is opened up called the "C++ Standard Library". This is a rich set of libraries that are present with all conformant C++ implementations and the ESP32 is no exception.
Here is the WikiPedia article:
https://en.wikipedia.org/wiki/C%2B%2B_Standard_Library
and one facet of this is the class called:
std::string
see ... https://en.wikipedia.org/wiki/C%2B%2B_string_handling
and now we have the full power of super rich string handling that "just works".
When writing apps in C++, one has access to all the APIs exposed by newlib and ESP-IDF but in addition, a new treasure chest is opened up called the "C++ Standard Library". This is a rich set of libraries that are present with all conformant C++ implementations and the ESP32 is no exception.
Here is the WikiPedia article:
https://en.wikipedia.org/wiki/C%2B%2B_Standard_Library
and one facet of this is the class called:
std::string
see ... https://en.wikipedia.org/wiki/C%2B%2B_string_handling
and now we have the full power of super rich string handling that "just works".
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
-
- Posts: 26
- Joined: Wed Dec 20, 2017 9:39 am
Re: How to use strings in esp idf?
Hello,
where can i find the strings.
this don´t work at all:
#include <string.h> or #include "string.h"
class WifiClass {
protected:
public:
string ssid[2]= { "braun","" };
std::string Host = "ESP8266_me";
class WifiClass {
protected:
public:
string ssid[2]= { "braun","" };
std::string Host = "ESP8266_me";
where can i find the strings.
this don´t work at all:
#include <string.h> or #include "string.h"
class WifiClass {
protected:
public:
string ssid[2]= { "braun","" };
std::string Host = "ESP8266_me";
class WifiClass {
protected:
public:
string ssid[2]= { "braun","" };
std::string Host = "ESP8266_me";
Re: How to use strings in esp idf?
Howdy,
The header you wish to include is
#include <string>
See also:
https://stackoverflow.com/questions/901 ... -extension
The header you wish to include is
#include <string>
See also:
https://stackoverflow.com/questions/901 ... -extension
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
-
- Posts: 26
- Joined: Wed Dec 20, 2017 9:39 am
Re: How to use strings in esp idf?
Thanks
iit works
iit works
Re: How to use strings in esp idf?
Hello
this don´t work at all:
#include <stdio.h>
std::pwmSliderValue = "0";
I am unable to call these functions.
#include <string>
#include <iostream>
this don´t work at all:
#include <stdio.h>
std::pwmSliderValue = "0";
I am unable to call these functions.
#include <string>
#include <iostream>
- Attachments
-
- Capture.PNG (27 KiB) Viewed 22415 times
Re: How to use strings in esp idf?
You are compiling main.c, which is a C source file. You should rename this to main.cpp (and update your CMakeLists.txt or Makefiles accordingly) to have the tools recognize this as a C++ source file and compile it using the C++ compiler.
BTW, it's a lot easier to read the error messages if you cut and paste the text instead of posting a screenshot.
BTW, it's a lot easier to read the error messages if you cut and paste the text instead of posting a screenshot.
Who is online
Users browsing this forum: Baidu [Spider], Google [Bot] and 100 guests