Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 此处不允许使用函数定义:void encryption(ifstream encrypt_file、of stream key_out、of stream cipher_out){_C++ - Fatal编程技术网

C++ 此处不允许使用函数定义:void encryption(ifstream encrypt_file、of stream key_out、of stream cipher_out){

C++ 此处不允许使用函数定义:void encryption(ifstream encrypt_file、of stream key_out、of stream cipher_out){,c++,C++,我相信错误来自于void函数声明和定义之间的某个地方 在类中,我们一直在读取void函数中文件名的输入值,但是对于这个赋值,它们将在主类中读取 我希望能够读入主类中的值,然后我将稍后在我的encryption()和decryption()函数中使用加密和解密方法编写代码。考虑到代码是在主类中打开的,而不是在void函数中打开的,有什么建议吗 错误: 在函数“int main()”中:119:79:错误:函数定义 在“{”令牌无效解密(ifstream)之前此处不允许 解密_in,流密钥的_in,

我相信错误来自于void函数声明和定义之间的某个地方

在类中,我们一直在读取void函数中文件名的输入值,但是对于这个赋值,它们将在主类中读取

我希望能够读入主类中的值,然后我将稍后在我的encryption()和decryption()函数中使用加密和解密方法编写代码。考虑到代码是在主类中打开的,而不是在void函数中打开的,有什么建议吗

错误:

在函数“int main()”中:119:79:错误:函数定义 在“{”令牌无效解密(ifstream)之前此处不允许 解密_in,流密钥的_in,流明文的_out){ ^125:80:错误:此处不允许在“{”之前使用函数定义 令牌无效加密(ifstream encryption_文件、ofstream keys_out、, 流密码(输出){ ^125:80:错误:此处不允许在“{”之前使用函数定义 代币

#包括
#包括
#包括
#包括
使用名称空间std;
无效解密(ifstream&decrypt_in,ifstream&keys_in,of Stream&
明信片(U out);
无效加密(ifstream&encryption\u in、ofstream&keys\u out、ofstream&
密文;
int main(){
枚举加密和解密{encrypt='E',decrypt='D'};
char enc_或_dec;
ifstream解密_in;
ifstream-encrypt_-in;
ifstream key_in;
流素输出;
流式键的输出;
流密码输出;
cout>enc_或dec;
如果(enc_或_dec=='e'){
enc_或_dec=加密;
}
如果(enc_或_dec=='d'){
enc_或_dec=解密;
}
while(加密和解密){
cout>enc_或dec;
}
开关(enc_或dec){
违约:
无法解密_文件;
cout>纯文本文件;
cout>keys\u文件;
在.open中解密(解密文件);
if(在.fail()中解密_){
cout-keys\u文件;
加密\u in.open(加密\u文件);
if(在.fail()中加密){

cout看起来您的函数定义实际上在main()的范围内,这是不允许的。请尝试移动悬空“}”文件末尾有几行。

你的大括号与你认为的不匹配。错误消息告诉你,你不能在定义它的地方定义一个函数-它实际上在
main()
中。请在下面引用你的代码:

int main() {
    ...
    switch(enc_or_dec) {
    ...
} // (1) <-- closing switch() statement

void decryption(ifstream& decrypt_in, ofstream& keys_in, ofstream& plaintxt_out) {
    decrypt_in.close();
    keys_in.close();
    plaintxt_out.close();
}

void encryption(ifstream& encrypt_file, ofstream& keys_out, ofstream& cipher_out) {
    encrypt_file.close();
    keys_out.close();
    cipher_out.close();
}

} // (2) <-- closing main()
intmain(){
...
开关(enc_或dec){
...

}//(1)不确定我的代码顶部是如何丢失缩进的;对此表示抱歉。许多行代码…报告的错误在哪一行,确切的消息是什么?@RichardCriten,我编辑并包含了错误消息,以及错误发生的正确行号。谢谢!投票以打字错误结束。错过了“}'导致函数在
main
中定义,这是错误指定的不允许的。因此,我继续这样做了,现在我有了一条新的错误消息。(.text+0x508):未定义对`加密(std::basic\u ifstream&,std::basic\u ofstream&,std::basic\u ofstream&)的引用'collect2:错误:ld返回了1个出口status@Gbrandonconner这将是一个新问题。我发现了!我无意中在函数定义中使用了与声明不同的名称,并且在解密的declaration中使用了两个ofstream和一个ifstream,但在定义中使用了一个ofstream和两个ifstream执行此操作----------------->“(.text+0x508):未定义对`加密(std::basic_ifstream&,std::basic_of stream&,std::basic_of stream&)'集合的引用2:错误:ld返回了1个退出状态”我复制并尝试了你的代码。我没有得到那个错误,但我得到了两个不同的编译器错误:首先,从重新定义
密钥\u文件
。你不能在两个不同的
case
语句中声明同一个变量-最好将
DECRYPT
ENCRYPT
的内容放在它们自己的块中(例如,
case DECRYPT:{…break;}
)。其次,更类似于您当前的错误-问题在于
decryption的声明
(在main上方)第二个参数是type
ifstream
,而定义使用了流的
,可能是一个打字错误。修复这些,它可能会工作。它工作了!就在您发送此文件之前,我根据另一篇stackoverflow文章进行了检查并找到了答案。非常感谢您的帮助。
int main() {
    ...
    switch(enc_or_dec) {
    ...
} // (1) <-- closing switch() statement

void decryption(ifstream& decrypt_in, ofstream& keys_in, ofstream& plaintxt_out) {
    decrypt_in.close();
    keys_in.close();
    plaintxt_out.close();
}

void encryption(ifstream& encrypt_file, ofstream& keys_out, ofstream& cipher_out) {
    encrypt_file.close();
    keys_out.close();
    cipher_out.close();
}

} // (2) <-- closing main()