I'm developing a project on my arduino board, for my projection of the idea I wrote the code in C++
. But certain library files and functions weren't found on the arduino IDE which are found in C++
to my knowledge.
I'm attaching the code below.
I want to convert the whole code into arduino in which only the convertToEnglish
will remain as a function in the arduino .
I tried replacing the header files and others functions with string library and other Stream.h
header file but almost everything ended up in vain.
Hence to over come this please quote me a solution.
I tried using Standard c++ as quoted but still the getline fucntion reports an error stating that the cin was not declared in scope.
#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;
}
error message: Arduino: 1.6.8 (Windows 8.1), Board: "Arduino/Genuino Uno"
E:\brain\arduino\sketch_mar15a\Blink\Blink\Blink.ino: In function 'int main()':
Blink:19: error: 'cin' was not declared in this scope
getline(cin, input);
^
exit status 1 'cin' was not declared in this scope
This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.
currentLetter
: beforeindex < characters
and aftercurrentLetter != morseCode[index]
. Otherwise you can accesmorseCode[26]
– max66