Issue with custom C++ Library using <string>

I wrote a custom library that uses the C++ <string> library. I was able to load the library into the IDE successfully using a .zip approach. When I attempt to compile the *.ino file, I get the following message. I'm used to this message when I don't have the proper library installed.

This is a c++ standard library, is there something I need to do include it as well?

fatal error: string: No such file or directory
 #include <string>
compilation terminated.
exit status 1

Arduino uses it own different 'string' library based on the String object.
See the String() - Arduino Reference
Also check out my tutorial on Taming Arduino Strings
for a fixed sized char[ ] replacement see my SafeString library which offers similar functionality to Arduino Strings but without the dynamic memory allocation

Thank you for this information! The goal with this library is to be a reusable library across many boards, Arduinos being one. I don’t want the custom library to have any dependency on Arduino libraries.

Is there some type of compile flag that can be updated? My next step is to precompile the library and see if that works.

SafeStrings (as with Arduino Strings) uses c-string methods underneath, but makes reference to other Arduino includes like Serial and some non-standard methods.
You can strip either of them down as you wish.

Is your library named "string"? If so, it's a bad choice since there's already a library named "String".

Did you try:
#include <string.h>

You could also look up the source code for C++ string library and include that with a namespace to make it unique.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.