【发布时间】:2016-04-18 16:32:11
【问题描述】:
我正在我的 arduino 板上开发一个项目,为了展示我在 C++ 中编写代码的想法。但据我所知,在 C++ 中找到的 arduino IDE 上没有找到某些库文件和函数。
我附上下面的代码。
我想将整个代码转换为 arduino,其中只有 convertToEnglish 将作为函数保留在 arduino 中。
我尝试用字符串库和其他Stream.h 头文件替换头文件和其他函数,但几乎一切都徒劳无功。
因此,要解决这个问题,请引用我的解决方案。
我尝试使用引用的Standard c++,但 getline 函数仍然报告错误,指出 cin 未在范围内声明。
#include <StandardCplusplus.h>
#include <system_configuration.h>
#include <unwind-cxx.h>
#include <utility.h>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
string convertToEnglish(string morse, string const morseCode[]);
int main()
{
string input = "";
cout << "Please enter a string in morse code: ";
getline(cin, input);
string const morseCode[] = {".-", "-...", "-.-.", "-..", ".", "..-.",
"--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-",
".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
cout << convertToEnglish(input, morseCode) << endl;
return 0;
}
string convertToEnglish(string morse, string const morseCode[])
{
string output = "";
string currentLetter = "";
istringstream ss(morse);
size_t const characters = 26;
while(ss >> currentLetter)
{
size_t index = 0;
while(currentLetter != morseCode[index] && index < characters)
{
++index; //increment here so we don't have to decrement after the loop like if we put in the condition
}
output += 'A' + index;
}
return output;
}
错误信息: Arduino:1.6.8(Windows 8.1),板:“Arduino/Genuino Uno”
E:\brain\arduino\sketch_mar15a\Blink\Blink\Blink.ino:在函数'int main()'中:
Blink:19: 错误:'cin' 未在此范围内声明
getline(cin, input);
^
退出状态 1 'cin' 未在此范围内声明
此报告将包含更多信息 “在编译期间显示详细输出” 文件 -> 首选项中启用的选项。
【问题讨论】:
-
到底是什么问题?
-
在arduino ide中找不到string和sstream头文件。如果不是 wat 是用于产生相同输出的其他头文件
-
Vectors in Arduino的可能重复
-
你应该切换
currentLetter的测试顺序:在index < characters之前和currentLetter != morseCode[index]之后。否则你可以访问morseCode[26]
标签: c++ function c++11 arduino header-files