pScore.begin();
it != groupScore.end() && count_WinSpeaker < 3;
++it, ++count_WinSpeaker)
{
if (this->m_Round == 1)
{
v2.push_back(it->second);
}
else
{
v_Victory.push_back(it->second);
}
}
//每分6个人清空一次容器
groupScore.clear();
//美观代码
if (grouping == 6) { std::cout << std::endl; }
}
}
std::cout << "==========第" << this->m_Round << "轮比赛结束==========" << std::endl;
system("pause");
}
void SpeechManager::showScore()
{
std::cout << "==========第" << this->m_Round << "轮比赛名次==========" << std::endl;
std::vector<int> v;
if (this->m_Round == 1)
{
v = v2;
}
else
{
v = v_Victory;
}
for (std::vector<int>::iterator it = v.begin(); it != v.end(); it++)
{
std::cout
<< "选手编号: " << *it << " "
<< "选手姓名: " << this->m_Speaker[*it].m_Name << " "
<< "选手分数: " << this->m_Speaker[*it].m_Score[this->m_Round - 1]
<< std::endl;
}
system("pause");
system("cls");
this->show_Menu();
}
void SpeechManager::saveRecord()
{
std::ofstream ofs("speech.csv", std::ios::out | std::ios::app);
for (std::vector<int>::iterator it = v_Victory.begin(); it != v_Victory.end(); it++)
{
ofs << *it << "," << this->m_Speaker[*it].m_Score[1] << ",";
}
ofs << std::endl;
std::cout << "保存分数完成" << std::endl;
std::cout << "本届比赛正式结束!" << std::endl;
this->fileIsEmpty = false;
system("pause");
system("cls");
}
void SpeechManager::loadRecord()
{
std::ifstream ifs("speech.csv", std::ios::in);
if (!ifs.is_open())
{
//std::cout << "文件不存在" << std::endl;
this->fileIsEmpty = true;
ifs.close();
return;
}
char ch;
ifs >> ch;
if (ifs.eof())
{
//std::cout << "文件为空" << std::endl;
this->fileIsEmpty = true;
ifs.close();
return;
}
//文件不为空
this->fileIsEmpty = false;
ifs.putback(ch);
std::string data;
int round = 0;
while (ifs >> data)
{
//定义获取往届比赛信息的容器
std::vector<std::string> v;
int pos = -1; //,号的标志位
int start = 0;
while (true)
{
//寻找 以","号分割的字符串,找不到就结束
pos = data.find(",", start);
if (pos == -1)
{
break;
}
//substr(起始位置, 结束位置)
std::string temp = data.substr(start, pos - start);
start = pos + 1;
v.push_back(temp);
}
//将往届的冠军数据插入到容器中
this->m_Record.insert(std::map<int, std::vector<std::string>>::value_type(round, v));
++round;
}
ifs.close();
}
void SpeechManager::showRecord()
{
if (this->fileIsEmpty)
{
std::cout << "文件不存在,记录为空" << std::endl;
}
else
{
for (int i = 0; i < this->m_Record.size(); i++)
{
std::cout
<< "=========第" << i + 1 << "届=========" << "\n"
<< " |