Question
I keep getting error: no matching function for call to 'getline(const ifstream&, std::__cxxll::string& Could you please fix the mistakes in this code? #include #include #include
#include
#include
#include
using namespace std;
string readInput(const ifstream fin)
{
string line=\"\";
string message=\"\";
while(!fin.eof()) // To get you all the lines.
{
getline(fin,line); // Saves the line in STRING.
message.append(line); // Append all the lines into a message .
}
return message;
}
void upperCase(string &tempMessage)
{
//clean up the message and make all upper case
for(int i = 0; i
tempMessage[i] = toupper(tempMessage[i]);
}
string cipher(string tempMessage)
{
//Encode the message through KeyBoard Cipher
for(int i = 0; i
char letter = tempMessage[i];
switch (letter){
case 'A':
letter = 'Q';
break;
case 'B':
letter = 'W';
break;
case 'C':
letter = 'E';
break;
case 'D':
letter = 'R';
break;
case 'E':
letter = 'T';
break;
case 'F':
letter = 'Y';
break;
case 'G':
letter = 'U';
break;
case 'H':
letter = 'I';
break;
case 'I':
letter = 'O';
break;
case 'J':
letter = 'P';
break;
case 'K':
letter = 'A';
break;
case 'L':
letter = 'S';
break;
case 'M':
letter = 'D';
break;
case 'N':
letter = 'F';
break;
case 'O':
letter = 'G';
break;
case 'P':
letter = 'H';
break;
case 'Q':
letter = 'J';
break;
case 'R':
letter = 'K';
break;
case 'S':
letter = 'L';
break;
case 'T':
letter = 'Z';
break;
case 'U':
letter = 'X';
break;
case 'V':
letter = 'C';
break;
case 'W':
letter = 'V';
break;
case 'X':
letter = 'B';
break;
case 'Y':
letter = 'N';
break;
case 'Z':
letter = 'M';
break;
default :
break;
}
tempMessage[i] = letter;
}
return tempMessage;
}
void translateLetterKeyboard(char letter)
{
switch (letter){
case 'A':
letter = 'Q';
break;
case 'B':
letter = 'W';
break;
case 'C':
letter = 'E';
break;
case 'D':
letter = 'R';
break;
case 'E':
letter = 'T';
break;
case 'F':
letter = 'Y';
break;
case 'G':
letter = 'U';
break;
case 'H':
letter = 'I';
break;
case 'I':
letter = 'O';
break;
case 'J':
letter = 'P';
break;
case 'K':
letter = 'A';
break;
case 'L':
letter = 'S';
break;
case 'M':
letter = 'D';
break;
case 'N':
letter = 'F';
break;
case 'O':
letter = 'G';
break;
case 'P':
letter = 'H';
break;
case 'Q':
letter = 'J';
break;
case 'R':
letter = 'K';
break;
case 'S':
letter = 'L';
break;
case 'T':
letter = 'Z';
break;
case 'U':
letter = 'X';
break;
case 'V':
letter = 'C';
break;
case 'W':
letter = 'V';
break;
case 'X':
letter = 'B';
break;
case 'Y':
letter = 'N';
break;
case 'Z':
letter = 'M';
break;
default :
break;
}
}
string translateLetterMorseCode(char letter)
{
string output = \"\";
switch(letter){
case 'A':
output = \".- \";
break;
case 'B':
output = \"-... \";
break;
case 'C':
output = \"-.-. \";
break;
case 'D':
output = \"-.. \";
break;
case 'E':
output = \". \";
break;
case 'F':
output = \"..-. \";
break;
case 'G':
output = \"--. \";
break;
case 'H':
output = \".... \";
break;
case 'I':
output = \".. \";
break;
case 'J':
output = \".--- \";
break;
case 'K':
output = \"-.- \";
break;
case 'L':
output = \".-.. \";
break;
case 'M':
output = \"-- \";
break;
case 'N':
output = \"-. \";
break;
case 'O':
output = \"--- \";
break;
case 'P':
output = \".--. \";
break;
case 'Q':
output = \"--.- \";
break;
case 'R':
output = \".-. \";
break;
case 'S':
output = \"... \";
break;
case 'T':
output = \"- \";
break;
case 'U':
output = \"..- \";
break;
case 'V':
output = \"...- \";
break;
case 'W':
output = \".-- \";
break;
case 'X':
output = \".-- \";
break;
case 'Y':
output = \"-.-- \";
break;
case 'Z':
output = \"--.. \";
break;
case ' ':
output = \" \";
break;
case '1':
output = \".---- \";
break;
case '2':
output = \"..--- \";
break;
case '3':
output = \"...-- \";
break;
case '4':
output = \"....- \";
break;
case '5':
output = \"..... \";
break;
case '6':
output = \"-.... \";
break;
case '7':
output = \"--... \";
break;
case '8':
output = \"---.. \";
break;
case '9':
output = \"----. \";
break;
case '0':
output = \"----- \";
break;
default:
output = letter;
}
return output;
}
void printOutput(string userInput,string encodedMessage)
{
cout
}
int main()
{
cout
//Prompt the user for a string
string userInput =\"\";
ifstream fin(\"input.txt\");
userInput = readInput(&fin);
string tempMessage =userInput;
upperCase(&tempMessage);
tempMessage = cipher(tempMessage);
//Encode the message through KeyBoard Cipher a second time
for(int i = 0; i
char letter = tempMessage[i];
translateLetterKeyboard(&letter) ;
}
//encode the message through Morse code
string encodedMessage = \"\";
for(int i = 0; i
encodedMessage += translateLetterMorseCode(tempMessage[i]);
}
//Print the output
printOutput(userInput,encodedMessage);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started