呼び出している関数を使用してベクトルを構築しようとしていますvector<Competition> CompPop()
。type である vector info を返したいですvector<Competition>
。以下は、Competition
クラスのベクトルとヘッダーを返す関数のコードです。
次のエラーが表示されます (私は Visual Studio を使用していますが、エラー メッセージは非常に基本的なものであり、実際に何が間違っているのか推測できます)。
- エラー C2065: '競争': 宣言されていない識別子
「CompPop」は未定義のクラス「std::vector」を使用します
「競争」: 宣言されていない識別子
エラー C2133: '情報': 不明なサイズ
エラー C2512: 'std::vector': 適切な既定のコンストラクターがありません
エラー C2065: '競合': 宣言されていない識別子
エラー C2146: 構文エラー: ';' がありません 識別子「temp」の前
エラー C3861: 'temp': 識別子が見つかりません
エラー C2678: バイナリ '[' : 型 'std::vector' の左側のオペランドを取る演算子が見つかりません (または、受け入れ可能な変換がありません)
#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;
}
私の競争ヘッダー:
#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;
};