我正在尝试从输入文件创建一个数组向量,然后将该向量加载到我的主文件中。我也尝试在整个程序中使用相同的向量。然而,当我编译时,我得到了一堆错误 LNK2019。我想我知道这发生在哪里,但我不确定为什么。有人可以帮忙或解释一下吗?谢谢!
#include <iostream>
#include <string>
#include <vector>
#include "Database.h"
#include "Registration.h"
#include "Competition.h"
#include "Events.h"
#include "CompPop.h"
#include "PushRegistration.h"
using namespace std;
void main()
{
vector<Competition> myVector = CompPop();
vector<Registration> myRegistration = PushRegistration();
Database home(myVector, myRegistration);
home.Menu();
system("pause");
}
似乎发生在:1.vector< Competition> myVector 2.vector<Registration> myRegistration
这些是我收到的错误消息
错误 LNK2001:未解析的外部符号“公共:__thiscall Registration::~Registration(void)”(??1Registration@@QAE@XZ)
和
错误 LNK2001:未解析的外部符号“公共:__thiscall Database::~Database(void)”(??1Database@@QAE@XZ)
我的 Compop 标头,从文件中读取并将内容存储到 Competition 的向量中(类似于我的 PushRegistration 标头)
#pragma once
#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
#include <vector>
#include "LogIn.h"
#include "Registration.h"
#include "Events.h"
#include "Competition.h"
using namespace std;
vector<Competition> CompPop()
{
ifstream myfile("PSU Results.txt");
string line, tcomp, tleader, tfollower, tevents, tplacement;
vector<Competition> info;
if(myfile.is_open())
{
int i = 0; // finds first line
int n = 0; // current vector index
int space;
while(!myfile.eof())
{
getline(myfile,line);
if(line[i] == '*')
{
space = line.find_first_of(" ");
tleader = line.substr(0+1, space);
tfollower = line.substr(space + 1, line.size());
}
else
{
if(line[i] == '-')
{
tcomp = line.substr(1, line.size());
Competition temp(tcomp, tleader, tfollower);
info[n] = temp;
}
else
{
if(!line.empty())
{
line = line;
space = line.find_first_of(",");
tevents = line.substr(0, space);
tplacement = line.substr(space + 2, line.size());
info[n].pushEvents(tevents,tplacement);
}
if(line.empty())
{
n++;
}
}
}
}
}
else
{
cout << "Unable to open file";
}
myfile.close();
return info;
}
我的比赛标题(类似于我的注册标题):
#pragma once
#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
#include <vector>
#include "LogIn.h"
#include "Registration.h"
#include "Events.h"
using namespace std;
struct Competition
{
public:
Competition(string compName, string lead, string follow)
{
Name = compName;
Leader = lead;
Follower = follow;
}
void pushEvents(string name, string place)
{
Events one(name, place);
Eventrandom.push_back(one);
}
string GetName()
{
return Name;
}
string GetLeader()
{
return Leader;
}
string GetFollow()
{
return Follower;
}
string GetEvent()
{
return Event;
}
string GetScore()
{
return Score;
}
void Print()
{
cout << "Leader: " << Leader << endl;
cout << "Follower: " << Follower << endl;
cout << "Competition: " << Name << endl;
cout << "Events and Placement: " << endl;
for(vector<Events>::iterator pos = Eventrandom.begin(); pos != Eventrandom.end(); ++pos)
{
cout << pos->eventName << " " << pos->Placement << endl;
}
cout << endl;
}
~Competition();
private:
string Name, Leader, Follower, Event, Score;
vector<Events> Eventrandom;
};
我的注册标题:
#pragma once
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
#define MAX_LENGTH 7
#define MAX_DANCES 9
class Registration
{
public:
Registration();
Registration(string confirmationCode, string follower, string leader, string comp, string level, string dance);
void FirstTime();
void infoFollower();
void infoLeader();
string gen_random(const int len);
string Levels();
string Dances();
void Print();
void print2Confirmation();
~Registration();
private:
string CCode, Follower, Leader, Name;
string Level, Dance;
};