I am busy with a practical. I have to enter a string or a message and have to convert it to Morse code:
‘A’ = .-
‘B’ = -…
ecs.
I can do that with no problem by using a series of if statements.
for(int i = 0;i < stringvalue.length();i++)
{
if(stringvalue == 'A')
cout << ".-";
//there is 26 if statements
}
But when i enter a string, eg.
"Testing data"
Only the first part of the string is converted(test is converted) to Morse.
Why does it not convert the part after the space. If there is a space in the string it must output “/ “.
If your input routine looks like this:
The input is read up to the first whitespace character. To read the whole line, you can use
std::getline.