我正在用 C++ 为 Arduino 编写一个堆栈类sketch http://www.arduino.cc/en/Tutorial/Sketch。我相信它完全符合AVR(如果这就是它的名字;我记不清了)编译器;我都用过malloc
and free
代替new
and delete
等等。
所以我的班级有一个 .h 文件。我已将其导入草图中,但是当我尝试编译时,出现以下错误:
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
这是我的课程的前几行:
#include <string>
using namespace std;
void Error(string message) {
所以Arduino编译器找不到<string>
,接下来的几个问题似乎与之相关(不确定是什么variable or field Error declared void
意味着,我的错误函数仅用于调试目的)。
我知道 Arduino 草图支持字符串,无需导入,但我不确定 C/C++/.h 文件如何实现。我尝试用谷歌搜索它,但没有太多文档。
Arduino 草图不支持任何 C++ 标准库,因为它们是使用avr-libc 不支持 http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_cplusplus。然而,Arduino 确实提供了String http://arduino.cc/en/Reference/StringObject类应该可以满足您的需要。
如果您正在编写一个库,您还需要#include <Arduino.h>
(or #include <Wiring.h>
如果您使用的是 Arduino IDE 1.0 之前的版本)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)