Read from file.
This commit is contained in:
parent
ad764a2263
commit
0117fea3f5
@ -1,5 +1,73 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
std::string slurp(std::ifstream& in) {
|
||||
std::ostringstream sstr;
|
||||
sstr << in.rdbuf();
|
||||
return sstr.str();
|
||||
}
|
||||
|
||||
struct ScoreData{
|
||||
int difficulty;
|
||||
std::string song;
|
||||
int totalEX;
|
||||
int ex1,ex2,ex3;
|
||||
std::string str()const{
|
||||
return "["+std::to_string(difficulty)+"] "+song+": "+std::to_string(totalEX)+" total, "+" EX1: "+std::to_string(ex1)+" EX2: "+std::to_string(ex2)+" EX3: "+std::to_string(ex3);
|
||||
}
|
||||
friend std::ostream&operator<<(std::ostream&os,const ScoreData&data){
|
||||
os<<data.str();
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
std::string GetNext(int&marker,std::string str){
|
||||
int originalMarker=marker;
|
||||
marker=str.find_first_of(',',originalMarker)+1;
|
||||
return str.substr(originalMarker,marker-1);
|
||||
};
|
||||
|
||||
int main(){
|
||||
std::cout<<"Hello World!"<<std::endl;
|
||||
|
||||
std::vector<ScoreData>dataA,dataB;
|
||||
std::ifstream file("team.csv");
|
||||
std::string line;
|
||||
//First two lines are garbage data.
|
||||
std::getline(file,line);
|
||||
std::getline(file,line);
|
||||
for(int i=0;i<12;i++){
|
||||
std::getline(file,line);
|
||||
int marker=0;
|
||||
dataA.emplace_back(ScoreData{
|
||||
stoi(GetNext(marker,line)),
|
||||
GetNext(marker,line),
|
||||
stoi(GetNext(marker,line)),
|
||||
stoi(GetNext(marker,line)),
|
||||
stoi(GetNext(marker,line)),
|
||||
stoi(GetNext(marker,line))}
|
||||
);
|
||||
}
|
||||
//Two more lines of garbage data.
|
||||
std::getline(file,line);
|
||||
std::getline(file,line);
|
||||
for(int i=0;i<12;i++){
|
||||
std::getline(file,line);
|
||||
int marker=0;
|
||||
dataB.emplace_back(ScoreData{
|
||||
stoi(GetNext(marker,line)),
|
||||
GetNext(marker,line),
|
||||
stoi(GetNext(marker,line)),
|
||||
stoi(GetNext(marker,line)),
|
||||
stoi(GetNext(marker,line)),
|
||||
stoi(GetNext(marker,line))}
|
||||
);
|
||||
}
|
||||
|
||||
for(auto&list:{dataA,dataB}){
|
||||
for(auto&dat:list){
|
||||
std::cout<<dat<<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user