这是我的代码,出于某种原因,它声称存在未声明的标识符,尽管我确实声明了所有内容
#include <iostream>
#include <string>
#include <fstream>
#include <iterator>
#include <algorithm>
using namespace std;
char a;
char caesarCipher (char );
char caesarDecipher (char );
string input;
string line;
std::string str;
void displayMenu() {
cout<<"This program will encrpt/decrypt files";
cout<<"To encrypt press 'e'/To decrypt press 'd'";
cin>>a;
}
void encrypt() {
string filename,ofilename;
cout << "Input filename: ";
cin >> filename;
cout << "Output filename: ";
cin >> ofilename;
ifstream infile(filename);
ofstream outfile(ofilename);
if ((infile >> noskipws) && outfile) {
std::transform(istream_iterator<char>(infile),
istream_iterator<char>(),
ostream_iterator<char>(outfile),
ceaserCipher);
string output = "";
for(int x = 0; x < input.length(); x++) {
output += ceaserCipher(input[x]);
}
}
}
/**************************************************************
* This function decrypts the content of infile and saves the *
* decrypted text into outfile *
* @param infile string (file that has encrypted text) *
* @param outfile string (file that will have decrypted text) *
**************************************************************/
void decrypt() {
string filename,ofilename;
cout << "Input filename: ";
cin >> filename;
cout << "Output filename: ";
cin >> ofilename;
ifstream infile(filename);
ofstream outfile(ofilename);
if ((infile >> noskipws) && outfile) {
std::transform(istream_iterator<char>(infile),
istream_iterator<char>(),
ostream_iterator<char>(outfile),
ceaserDecipher);
string output = "";
for(int x = 0; x < input.length(); x++) {
output += ceaserDecipher(input[x]);
}
}
}
/**************************************************************
* This function takes an character and a cipher key to return*
* an encrypted character. *
* @param c is a char (the character to be encrypted) *
* @param key is an integer (cipher key given in the handout) *
**************************************************************/
char ceaserCipher(char c) {
if (isalpha (c)) {
c = toupper(c);
c = (((c-65)+5) % 26) + 65;
}
return c;
}
char ceaserDecipher(char c) {
if (isalpha (c)) {
c = toupper(c);
c = (((c-65)-5) % 26) + 65;
}
return c;
}
int main() {
char b;
displayMenu();
if (a=='e'||a=='E') {
encrypt;
}
else (a=='d'||a=='D'); {
decrypt;
}
cout<<"To exit input 'e'/To continue press 'c'";
cin>>b;
switch (b) {
case 'c':
return main();
case 'e':
return 0;
break;
}
}
这些是错误:
停止者密码':未声明的标识符 停止密码':未找到标识符 停止者解码器':未声明的标识符 停止者解密器':未找到标识符
任何和所有的帮助表示赞赏