【发布时间】:2014-04-24 01:35:18
【问题描述】:
我正在尝试创建一个基本的登录页面,但是当我尝试构建程序时,出现语法错误。
这是我得到的错误:
Error 1 error LNK2019: unresolved external symbol "struct UserRecord __cdecl ReadData(class
std::basic_ifstream<char,struct std::char_traits<char> > &,struct UserRecord)" (?ReadData@@YA?
AUUserRecord@@AAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@U1@@Z) referenced in function _main
c:\Users\Emerson\documents\visual studio
2012\Projects\ConsoleApplication11\ConsoleApplication11\small_eas12d_p6.obj ConsoleApplication11
当程序从我能得到的内容中调用主函数时,我得到了两次相同的错误。但是我想不出办法来解决它。
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int Max_Persons = 50, Max_Attempts = 3;
struct UserRecord
{
string userID;
string password;
int PIN;
};
typedef struct UserRecord AccountInfo;
void PrintHeading();
void Login_Success();
void Kicked();
void Login_Failed(int);
void FileCheck(ifstream &);
UserRecord ReadData(ifstream &, AccountInfo);
bool checkData(bool, AccountInfo, int);
int main()
{
int i = 0;
bool passorfail = false;
int attempts = 0;
ifstream infile;
AccountInfo Accounts[Max_Persons];
FileCheck(infile);
Accounts[Max_Persons] = ReadData(infile, Accounts[Max_Persons]);
PrintHeading();
do
{
passorfail = checkData(passorfail, Accounts[Max_Persons], attempts);
} while (!passorfail || attempts < 3);
if (attempts <= 3)
Kicked();
if(passorfail)
Login_Success();
infile.close();
return 0;
}
AccountInfo ReadData(ifstream & infile, AccountInfo Accounts[Max_Persons])
{
int UserNum;
string str;
getline(infile, str, '\n' );
UserNum = atoi(str.c_str());
for(int i = 0; i < UserNum; i++)
{
infile >> Accounts[i].userID;
infile >> Accounts[i].password;
infile >> Accounts[i].PIN;
}
return Accounts[Max_Persons];
}
void FileCheck(ifstream & infile)
{
string FileName;
cout << "Filenames must not contain blanks ." << endl;
cout << "Please enter the file name to decode ->" << endl;
cin >> FileName;
infile.open(FileName.c_str());
while(!infile)
{
FileName.clear();
cout << "Sorry \"" << FileName << "\" is not a valid file name. Please try again." << endl;
cin >> FileName;
infile.open(FileName.c_str());
}
return;
}
bool checkData(bool passorfail, AccountInfo Accounts[Max_Persons], int attempts)
{
string givenID;
string givenPass;
int givenPin;
do
{
cout << "Login" << endl;
cout << "UserID: ";
cin >> givenID;
cout << endl << "Password: ";
cin >> givenPass;
cout << endl << "Pin: ";
cin >> givenPin;
for(int i = 0; i < Max_Persons; i++)
{
if(givenID == Accounts[i].userID)
{
if (givenPass == Accounts[i].password)
{
if (givenPin == Accounts[i].PIN)
{
passorfail = true;
}
}
}
}
if(!passorfail)
{
Login_Failed(attempts);
attempts++;
}
} while (!passorfail || attempts < 3);
return passorfail;
}
void PrintHeading()
{
cout << "-----------------------------------------------------------\n";
cout << "------ Welcome to MyGreatWebsite.com ------\n";
cout << "-----------------------------------------------------------\n";
cout << "**Unauthorized access to this stie is strictly prohibited**";
return;
}
void Login_Failed(int attempts)
{
cout << "Sorry, that username and/or password was incorrect" << endl;
cout << "You have used " << attempts << " of your attempts to login. " << endl;
cout << "You only have 3 attempts total before you are automatically " << endl;
cout << "kicked from the system" << endl;
return;
}
void Kicked()
{
cout << "Sorry, you have reached the maximum number attempts " << endl;
cout << "to access this site, please have a good day" << endl;
return;
}
void Login_Success()
{
cout << "Welcome to MyGeatWebsite.com" << endl;
cout << "Enjoy your stay" << endl;
return;
}
提前感谢您的帮助。
【问题讨论】:
标签: c++ visual-studio compiler-errors