私はユーザーに分割された5つの配列に分割されたキーワードを入力させ、次に "getletter"という名前の別の関数を配列の空白の中に入れます。アルファベット順に表示されます。キーワードの値をgetletter関数に渡そうとすると機能しません。char型変数を型文字列関数に渡す関数
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>
#include<limits>
using namespace std;
string getletter();
char type[81];
char filename[20];
char key [5];
char f[2] = "q";
char g[2] = "q";
char h[2] = "q";
char i[2] = "q";
char j[2] = "q";
char k[2] = "q";
char l[2] = "q";
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int main(){
string cipherarray[5][5]= {
{"a","f","k","p","v"},
{"b","g","l","r","w"},
{"c","h","m","s","x"},
{"d","i","n","t","y"},
{"e","j","o","u","z"}
};
cout<<"Enter the name of a file you want to create.\n";
cin>>filename;
cout<<"enter your codeword(codeword can have no repeating letters)\n";
cin>>key;
while (key[a] != '\0'){
while(b <= 4){
cipherarray[b][c] = key[a];
if ( f == "q") {
cipherarray[b][c] = f;
}
if (f != "q" && g == "q" )
{
cipherarray[b][c] = g;
}
if (g != "q" && h == "q")
{
cipherarray[b][c] = h;
}
if (h != "q" && i == "q" )
{
cipherarray[b][c] = i;
}
if (i != "q" && j == "q")
{
cipherarray[b][c] = j;
}
if (j != "q" && k == "q")
{
cipherarray[b][c] = k;
}
if (k != "q" && l == "q")
{
cipherarray[b][c] = l;
}
a++;
b++;
if (key[a] == 0)
break;
}
if (key[a] != 0){
c++;
b = 0;
}
}
while (c <= 4) {
while (b <= 4) {
cipherarray[b][c] = getletter();
b++;
}
b = 0;
c++;
}
b = 0;
c = 0;
while (c <= 4) {
while (b <= 4) {
cout<<cipherarray[b][c]<<" ";
b++;
}
cout<<endl;
b = 0;
c++;
}
cout<<"now enter some text."<<endl<<"To end this program press Crtl-Z\n";
ofstream outFile;
outFile.open(filename);
outFile<<fixed;
outFile.precision(2);
outFile.setf(ios_base::showpoint);
cin.ignore(std::numeric_limits<int>::max(),'\n');
while(!cin.fail()){
cin.getline(type,81);
outFile<<type<<endl;
}
outFile.close();
}
string getletter() {
string letter;
string cipherarraytemplate[5][5]= {
{"a","f","k","p","v"},
{"b","g","l","r","w"},
{"c","h","m","s","x"},
{"d","i","n","t","y"},
{"e","j","o","u","z"}
};
if (cipherarraytemplate[d][e] == f || cipherarraytemplate[d][e] == g || cipherarraytemplate[d][e] == h || cipherarraytemplate[d][e] == i || cipherarraytemplate[d][e] == j ||
cipherarraytemplate[d][e] == k || cipherarraytemplate[d][e] == l){
d++;
}
else {
letter = cipherarraytemplate[d][e];
}
d++;
if (d == 5){
e++;
d = 0;
}
return letter;
}
あなたが言っていることの半分しか理解していませんが、私は試してみます:) –
私はすべての私のif文に上記の文の形式が含まれていますが、まだ動作していません。ありがとう、私は今問題を知っているが、変数の値を渡すことではないことを知っているが応答します。 –
'j!=" q "'は2つのポインタwitchが決して等しくないことを比較します。より正確な解決策は、fist char: 'f [0]!= 'q' && g [0] == 'q''を比較することです。 – Arpegius