I am trying to build a vector using a function that I am calling vector<Competition> CompPop()
. I want to return the vector info which is a type vector<Competition>
. Below is my code for the function returning the vector and the header for my Competition
class.
I'm getting the following errors (I'm using Visual Studio and the error message are very basic, leaving me guessing as to what I am actually doing wrong):
-error C2065: 'Competition' : undeclared identifier
'CompPop' uses undefined class 'std::vector'
'Competition' : undeclared identifier
error C2133: 'info' : unknown size
error C2512: 'std::vector' : no appropriate default constructor available
error C2065: 'Competition' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'temp'
error C3861: 'temp': identifier not found
error C2678: binary '[' : no operator found which takes a left-hand operand of type 'std::vector' (or there is no acceptable conversion)
#pragma once
#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
#include <vector>
#include "LogIn.h"
#include "Registration.h"
#include "Tree.h"
#include "PriorityQueue.h"
#include "Events.h"
#include "Competition.h"
using namespace std;
vector<Competition> CompPop()
{
ifstream myfile("Results.txt");
string line, tcomp, tleader, tfollower, tevents, tplacement;
vector<Competition> info;
istringstream instream;
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;
}
my Competition header:
#pragma once
#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
#include <vector>
#include "LogIn.h"
#include "Registration.h"
#include "Tree.h"
#include "PriorityQueue.h"
#include "Events.h"
#include "CompPop.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;
}
~Competition();
private:
string Name, Leader, Follower, Event, Score;
vector<Events> Eventrandom;
};