私は、文字、数字、句読点をモールスコードに変換するプログラムを作っています。C++からASCIIコードをモールスコードに変換
文字と数字は私が望むように働いています。
しかし、句読点では、私はそれを正しく動作させることはできません。誰かが自分のコードを見て助けてくれることを願っていました。
while(ss >> word) { // <<<< Put an opening brace here
cout << EnglishToMorse(word) << endl;
cout << NumbersToMorse(word) << endl;
cout << PunctuationToMorse(word) << endl;
} // <<<<< ... and a closing brace here
A一般的により良いアプローチは、次のようになります:既知の
地図すべて
#include <iostream>
#include <cstring>
#include <sstream>
using namespace std;
char ch;
string morseWord = "";
for(unsigned int i=0; i < word.length(); i++)
{
if(isalpha(word[i]))
{
ch ;
}
}
return morseWord;
}
char ch;
string morseWord = "";
for(unsigned int i=0; i < word.length(); i++)
{
if(isdigit(word[i]))
{
ch = word[i];
ch = toupper(ch);
morseWord += morseCode[ch - '0'];
morseWord += " ";
string morseWord = "";
for(unsigned int i=0; i < word.length(); i++)
{
if(ispunct(word[i]))
{
ch = word[i];
ch = toupper(ch);
morseWord += morseCode[ch - '.'];
morseWord += " ";
}
}
return morseWord;
}
int main()
{
stringstream ss;
string sentence;
string word = "";
code: " << endl;
while(ss >> ToMorse(word) << endl;
cout << PunctuationToMorse(word) << endl;
}
ようこそスタックオーバーフロー。 [The Tour](http://stackoverflow.com/tour)を読み、[ヘルプセンター](http://stackoverflow.com/help/asking)の資料を参考にしてください。ここに聞いてください。 –
_ "句読点では、私はそれを正しく働かせることはできません" _実際の問題は何ですか?入力、期待される出力、実際の出力は何ですか? –
現時点で私は入力できるようにしたい:ドット、疑問符とeksklamationマーク。私はドットを入力すると、それは細かい変換します。 しかし、私は他の2つを入力すると、私には:?U ??? –