未声明的标识符/标识符未找到问题

时间:2013-04-03 14:50:25

标签: c++ undeclared-identifier

这是我的代码,由于某种原因,它声称有未声明的标识符,尽管我确实声明了所有内容

#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;
    }
}

这些是错误:

ceaserCipher' : undeclared identifier
ceaserCipher': identifier not found
ceaserDecipher' : undeclared identifier
ceaserDecipher': identifier not found

感谢任何和所有帮助

2 个答案:

答案 0 :(得分:3)

您拼错了函数名称。

char caesarDecipher (char );

当您尝试使用(以及稍后 - 定义)ceaserDecipher时(注意拼写的不同方式:“ceasEr”和“ceasAr”)。

答案 1 :(得分:2)

你的前瞻声明将其拼写为caesar,但你的函数定义拼写为ceasar。