c++11 - 无法理解 IO 目录和管道命令
问题描述
我试图通过根据数字移动字母并将其写入 f2.txt 来加密 f1.txt 文件。但我不确定 f1.txt 的内容是否进入 ./cf
$ 猫 f1.txt | ./cf -e 3 > f2.txt
int main(int argc, char ** argv){
char alpha[26] = {'A','B','C','D','E','F','G','H','I','J','K','L', // alphabet arr
'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//ifstream input(argv[0]);
string line = "";
if(input.fail()){
cout << "error opening file "<<endl;
exit(1);
}
string type = argv[1];
if(type == "-e"){
while(getline(input,line)){
char plain [line.length()]; // array to store plain text
strcpy(plain, line.c_str()); //putting input into char array
string cipher_text = ""; // variable to store plain text
int shift = atoi(argv[2]);
for(int x = 0; x < line.length(); x++){ //for loop runs through char array
//and add plain letter based on shift
if((char(plain[x]) >= 65) && (char(plain[x]) <= 90)){;
cipher_text += cipher_letter(alpha,shift,string(1,plain[x]));
}else
cipher_text += plain[x];
}
cout << cipher_text << endl;
}
}else if(type == "-d"){
while(getline(input,line)){
char cipher [line.length()]; // array to store plain text
strcpy(cipher, line.c_str()); //putting input into char array
string plain_text = ""; // variable to store plain text
int shift = atoi(argv[2]);
for(int x = 0; x < line.length(); x++){ //for loop runs through char array
//and add plain letter based on shift
if((char(cipher[x]) >= 65) && (char(cipher[x]) <= 90)){
plain_text += plain_letter(alpha,-shift,string(1,cipher[x]));
}else
plain_text += cipher[x];
}
cout<< plain_text << endl;
}
}
input.close();
}
解决方案
推荐阅读
- c# - 获取屏幕中心
- c# - .Net Core Docker 无法加载 DLL 'activeds.dll'
- google-apps-script - 延迟编辑功能以插入时间戳
- imagemagick - Imagemagick:将剪切区域应用于另一个图像
- performancecounter - 通过 Trace32 导出 BMC 跟踪流
- javascript - 从 JSON 列表中获取数据
- php - 在表格中整齐地显示与 ID 关联的记录
- python - Python-根据另一列的变化创建一个计数器列并重新启动计数器
- java - 使用 spring boot 石英创建表失败
- crossfilter - 是什么导致“未捕获 RangeError:超出最大调用堆栈大小”以及如何删除它?