-3
我必須將大寫字母轉換爲它的NATO拼音字母對應字符。使用兩個數組。C++數組中的北約字母
letters.txt是用字母AZ文本文件
words.txt與北約拼音字母阿爾法 - 祖魯
(實施例的文本文件:A =阿爾法,B = Bravo ...)
我遇到的問題是,每次轉換一個字母只會打印祖魯語。
我該如何添加或更改此程序才能正確轉換?
下面是代碼
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
ifstream inputFile;
inputFile.open("words.txt");
string word;
while (inputFile >> word)
{
}
inputFile.open("letters.txt");
char letter;
while (inputFile >> letter)
{
}
char choice;
char letter2;
char Alpha[26]={letter};
string Words[26]={word};
do
{
cout<<"\nPlease enter a letter"<<endl;
cout<<"Letter: ";
cin>>letter2;
for(int count=0; count < 26; count++)
{
cout<< Words[count];
}
cout<<"\nDo you want to run this program again? <y/n>"<<endl;
cin>>choice;
}
while(choice=='y' || choice=='Y');
return 0;
}
'而(INPUTFILE >>字){}'將簡單地取代以前'word'每次迭代。你只存儲一個字,最後一個讀。 'string words [26] = {word};'定義一個包含26個字符串的數組,第一個字是存儲在word中的任何字,其餘的都是空字符串。直接閱讀「單詞」和「字母」。 –
你需要從小開始,一次一步;首先將單個文件讀入內存。另請參閱[如何調試小程序](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。 –