C++ C++;编码错误
这段代码的目的是获取命令行参数./Program-encode | decode 0-9,并将其应用于写在下一行的文本字符串。如果进行编码,则将文本的每个字符移动到字母表中指定的位置。解码则相反。我已经做得足够好了,编译器没有发现任何错误,但是当运行程序时,在输入文本字符串后没有返回任何内容C++ C++;编码错误,c++,C++,这段代码的目的是获取命令行参数./Program-encode | decode 0-9,并将其应用于写在下一行的文本字符串。如果进行编码,则将文本的每个字符移动到字母表中指定的位置。解码则相反。我已经做得足够好了,编译器没有发现任何错误,但是当运行程序时,在输入文本字符串后没有返回任何内容 #include <iostream> #include <string> #include <cctype> #include <cstdlib> #inc
#include <iostream>
#include <string>
#include <cctype>
#include <cstdlib>
#include <cstring>
using namespace std;
string encode(string& to_encode, int to_shift)
{for(int i = 0; I < to_encode.length(); i++)
{if(isalpha(to_encode[i]))
{char sum = to_encode[i] + to_shift;
if(isupper(to_encode[i]) != 0 && isupper(sum) == 0)
{to_encode[i] = sum - 'Z' + 'A';
}
if(isupper(to_encode[i]) != 0 && isupper(sum) != 0)
{to_encode[i] = sum;
}
if(islower(to_encode[i]) != 0 && islower(sum) == 0)
{to_encode[i] = sum - 'z' + 'a';
}
if(islower(to_encode[i]) != 0 && islower(sum) != 0)
{to_encode[i] = sum;
}
}
}
return to_encode;
}
string decode(string& to_decode, int to_shift)
{for(int i = 0; I < to_decode.length(); i++)
{if(isalpha(to_decode[i]))
{char difference = to_decode[i] + to_shift;
if(isupper(to_decode[i]) != 0 && isupper(difference) == 0)
{to_encode[i] = difference + 'Z' - 'A';
}
if(isupper(to_decode[i]) != 0 && isupper(difference) != 0)
{to_encode[i] = difference;
}
if(islower(to_decode[i]) != 0 && islower(difference) == 0)
{to_encode[i] = difference + 'z' - 'a';
}
if(islower(to_decode[i]) != 0 && islower(difference) != 0)
{to_encode[i] = difference;
}
}
}
return to_decode;
}
int main(int argc, char* argv[])
{string cryption;
in shift;
if(argc != 3)
{cerr<<"Usage: ./Prog1d -encode|decode 0-9"<<endl;
return -1;
}
if(!(strcmp(argv[1],"-encode") == 0 || strcmp(argv[1],"-decode") == 0)
{cerr<<"Usage: ./Prog1d -encode|decode 0-9"<<endl;
return -1;
}
shift = atoi(argv[2]);
if(shift > 0 && shift <= 9)
{while(getline(cin,cryption))
{if(argv[1] == "-encode")
{encode(cryption, shift);
}
else
{decode(cryption, shift);
}
}
}
else
{cerr<<"Usage: ./Prog1d -encode|decode 0-9"<<endl;
return -1;
}
}
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
字符串编码(字符串和to_编码,int-to_移位)
{for(int i=0;i {Cerry您从不告诉您的程序在编码/解码完成后应该在屏幕上打印任何内容。因此,它不会打印任何内容。您是否使用旧的纸张滚动decwriter或类似的东西,其中任何一列英寸的文本都是宝贵的?请使用一些缩进和空白)。