I'm writing a stack class in C++ for an Arduino sketch. I believe it is fully compliant with the AVR (if that's what it's called; I can't remember exactly) compiler; I've used all malloc
and free
instead of new
and delete
and so on.
So I have a .h file with my class. I've imported it into the sketch, but when I try to compile, I get these errors:
In file included from sketch_may15a.cpp:1:
/CStack.h:58:18: error: string: No such file or directory
In file included from sketch_may15a.cpp:1:
CStack.h:61: error: variable or field 'Error' declared void
CStack.h:61: error: 'string' was not declared in this scope
And here are the first few lines for my class:
#include <string>
using namespace std;
void Error(string message) {
So the Arduino compiler can't find <string>
, and the next few problems seem to relate to it (not sure what variable or field Error declared void
means, my error function is just for debugging purposes).
I know Arduino sketches support strings without need for an import, but I'm not sure how that works out with C/C++/.h files. I've tried googling it, but there isn't much documentation.
Arduino sketches don't support any of the C++ standard library as they are compiled using avr-libc which doesn't support it. However, Arduino does provide the String
class which should do what you need.
If you are writing a library you'll also need to #include <Arduino.h>
(or #include <Wiring.h>
if you are using a pre-1.0 version of the Arduino IDE).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With