C++ 错误C3861:&x27;解密';即使在标头中有函数也找不到

C++ 错误C3861:&x27;解密';即使在标头中有函数也找不到,c++,visual-studio,compiler-errors,runtime-error,C++,Visual Studio,Compiler Errors,Runtime Error,我的代码加载了一个加密的文本文件,该文本文件的第一行是一个密码,用于解码文本文件的其余部分。我知道如果函数没有在main之前定义,通常会发生这个错误,但是我在头文件中定义了它,所以我不确定是什么导致了这个问题 #include <string> #include <iostream> #include <fstream> std::string decrypt(std::string cipher, std::string text); int main

我的代码加载了一个加密的文本文件,该文本文件的第一行是一个密码,用于解码文本文件的其余部分。我知道如果函数没有在main之前定义,通常会发生这个错误,但是我在头文件中定义了它,所以我不确定是什么导致了这个问题

#include <string>
#include <iostream>
#include <fstream> 

std::string decrypt(std::string cipher, std::string text);

int main()
{
//variable
std::string fileName; 
std::string cipher; 
std::string text;   

//prompt the user to enter the file name
std::cout << "Enter file name: "; 
std::cin  >> fileName;

//declare input stream
std::ifstream inFile(fileName); 

//Checks if the file has been connected or not
if (inFile.is_open()) 
{ 
    std::cout << "File found." << std::endl; 
    std::cout << "Processing..." << std::endl; 

    getline(inFile,cipher); //get the first line as one string
    std::cout << cipher << std::endl;  //TEST!!!!
    std::cout << "\n" << std::endl; //TEST!!!!!!

    while (inFile.good()) //continue running until an error occurs to get the rest of the text as second string
    {
        getline(inFile,text); //get the first line as one string
        std::cout << text << std::endl; //TEST!!!!
    }       
} 
else //if the file isn't connected
{ 
    std::cout << "File not found." << std::endl;    **(ERROR C3861 HERE)**
}

inFile.close(); //close the file

std::string finalResult = decrypt(cipher,text);
std:: cout << finalResult << std::endl;

return 0;
}

//Decrypt function: Takes 2 strings by reference, changes the second string into the    unencrypted text
std::string decrypt(std::string cipher, std::string text)
{

char alphabet[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //create a character array of the alphabet 
char code[27]; //empty array 
char oldText[500]; //empty array 
strcpy(code,cipher.c_str()); //copies the cipher into the array
strcpy(oldText,text.c_str()); //copies the encrypted text into the array

for (int i = 0; i < 500;i++) //Loop through the entire encrypted text
{
    int k = i; //creates and resets a variable for while loop
    while (alphabet[k] != oldText[i])
    {
        k = k+1; 
    }
    oldText[i] = alphabet[k]; //after a match is detected, swap the letters
}

std::string newText(oldText); // converts the array back into text
return newText;
}
#包括
#包括
#包括
std::字符串解密(std::字符串密码,std::字符串文本);
int main()
{
//变数
std::字符串文件名;
字符串密码;
std::字符串文本;
//提示用户输入文件名
std::cout>fileName;
//声明输入流
std::ifstream infle(文件名);
//检查文件是否已连接
if(infle.is_open())
{ 

std::cout您的问题是
解密中的这一行:

 std::string text(oldText); // converts the array back into text
它不会将“oldText”转换回
text
;而是声明一个名为
test
的新局部变量。该新局部变量与名为
text
的参数冲突。这是导致
C2082
的行。您应该编写的是:

text = oldText;
这就是用
oldText
中的内容替换
test
的内容,尽管完全跳过该内容并返回oldText
会更简单


我在编译代码时没有收到
C3861
,加上您在错误的行上显示
C2082
,这让我觉得您的源文件与错误不同步。

谢谢您的回复。我已经修复了C2082,但是,我仍然收到C3861的错误。我尝试将冷备份复制到新的cpp f中这一次,它说错误在第45行“getline(infle,text);//将第一行作为一个字符串获取”@user3550643
std::getline