0
私のラボの課題は、文字列を別のファイルからテキストファイルに暗号化することです。それはうまくいきますが、私の唯一の問題は暗号化を暗号化または解読するときですZとYの文字を省略しています。私はいくつかのものを変更しようとしましたが、何も動作しません。文字列zとyを省略した文字列
これはこれまでのところ私のコードです:
#include iostream
==
#include fstream
==
#include cstring
==
#include string
==
using namespace std;
int main()
{
ifstream inputFile;
ofstream outputFile;
const int SIZE=150;
char file[SIZE];
char message[SIZE+1];
char letter;
char alphabet[]={'A','B','C','D','E','F','G','H','I','J','K','L',
'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\0'};
cout<<"Enter the message you want to encrypt: "<<endl; //getmessage
cin.getline(message,SIZE,'\n');
for(int i=0;i<strlen(message);i++){
if(islower(message[i])) //change to
message[i]=toupper(message[i]); //uppercase
}
outputFile.open("textoNoEncrypt.txt");
for(int i=0;i<strlen(message);i++){ //copy message to
outputFile.put(message[i]); //file
}
outputFile.close();
inputFile.open("textoNoEncrypt.txt");
if (inputFile.is_open()){
int i=0;
while (!(inputFile=='\0')){
inputFile>>file[i]; //reading and copying
i++; //data from file
}
}
inputFile.close();
outputFile.open("textoEncrypt.txt");
for(int i=0;i<strlen(file);i++){
int j=0;
int P=0;
int index=0;
bool found=false;
while(!found){
if(file[i]==alphabet[j]){
P=j;
index=(P+3)%26; //encrypting message
file[i]=alphabet[index];
found=true;
cout<<j<<" ";
}
j++;
}
outputFile.put(file[i]);
}
outputFile.close();
cout<<message<<endl; //show original message
cout<<file<<endl; //show encrypted message
return 0;
}
'の#include iostream'がコンパイルできないことで原因だと思います。代わりに '#include'を使用してください。 –
ようこそスタックオーバーフロー。 [The Tour](http://stackoverflow.com/tour)を読み、[ヘルプセンター](http://stackoverflow.com/help/asking)の資料を参考にしてください。ここに聞いてください。 –
あなたのコードが本当にうまくいくなら、[SE Code Review](https://codereview.stackexchange.com/questions/ask)で改善を求めてください。 –