This my first ever code that I used comments and I know the commentation is not perfect. When I attempted to build my code, compiler gives me this error
no matching function for call to 'make_pair(char [len], int&).
I wanted to return two variable with std::pair
Pls notice: I just want to debug this code so do not write your own way to do what I want to at first stage.
I use gcc 5.1 and my OS is windows
/* this program takes an string from user and output its morse code equivalent */
#include <iostream>
#include <cstring>
#include <algorithm>
#include <utility>
using namespace std;
/* getString() is for getting a text with type std::string and converse all the letters in it
to lower case in order to switch case then converse std::string text type to cstring to be able to loop through it with
for loop*/
pair<const char*, int> getString()
{
string a;
getline(cin, a);
// converse all the letters in string a to lower case for switch case
transform(a.begin(), a.end(), a.begin(), ::tolower);
int len = a.length() + 1;
char ch[len];
strcpy(ch, a.c_str());
return make_pair(ch, len); //this line causing error
}
int main() {
p = pair<const char*, int> getString();
char ch = p.first;
int len = p.second;
string morseCode;
/*this for loop search in the ch character array and add morse code equivalent of each letter to morseCode
string Variab*/
for (int i = 0; i < len; i++)
switch(ch[i])
{
case ' ':
morseCode += "/ ";
break;
case 'a':
morseCode += ".- ";
break;
case 'b':
morseCode += "-... ";
break;
case 'c':
morseCode += "-.-. ";
break;
case 'd':
morseCode += "-.. ";
break;
case 'e':
morseCode += ". ";
break;
case 'f':
morseCode += "..-. ";
break;
case 'g':
morseCode += "--. ";
break;
case 'h':
morseCode += ".... ";
break;
case 'i':
morseCode += ".. ";
break;
case 'j':
morseCode += ".--- ";
break;
case 'k':
morseCode += "-.- ";
break;
case 'l':
morseCode += ".-.. ";
break;
case 'm':
morseCode += "-- ";
break;
case 'n':
morseCode += "-. ";
break;
case 'o':
morseCode += "--- ";
break;
case 'p':
morseCode += ".--. ";
break;
case 'q':
morseCode += "--.- ";
break;
case 'r':
morseCode += ".-. ";
break;
case 's':
morseCode += "... ";
break;
case 't':
morseCode += "- ";
break;
case 'u':
morseCode += "..- ";
break;
case 'v':
morseCode += "...- ";
break;
case 'w':
morseCode += ".-- ";
break;
case 'x':
morseCode += "-..- ";
break;
case 'y':
morseCode += "-.-- ";
break;
case 'z':
morseCode += "--.. ";
break;
}
cout << morseCode;
return 0;
}