无法了解IO目录和管道命令

时间:2019-01-21 01:02:23

标签: c++11 unix

im试图通过根据数字移字母来加密f1.txt文件并将其写入f2.txt。但我不确定f1.txt的内容是否进入./cf

$ cat 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();

}

0 个答案:

没有答案