1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#include <iostream>
#include <fstream>
#include <vector>
#include <exception>
enum class Note { A, B, C, D, E, F, G };
enum class String { E, A, D, G, B };
struct Pos
{
Note m_note;
int m_fret;
String m_string;
};
std::istream & operator>>( std::istream & is, String & string)
{
std::string tmp;
is >> tmp;
switch(tmp[0])
{
case 'E': string = String::E; break;
case 'A': string = String::A; break;
case 'D': string = String::D; break;
case 'G': string = String::G; break;
case 'B': string = String::B; break;
default:
//std::cout << (int)tmp[0];
throw std::runtime_error("Wrong_string:"+tmp+"!");
}
return is;
}
std::istream & operator>>( std::istream & is, Note & note)
{
std::string tmp;
is >> tmp;
switch(tmp[0])
{
case 'A': note = Note::A; break;
case 'B': note = Note::B; break;
case 'C': note = Note::C; break;
case 'D': note = Note::D; break;
case 'E': note = Note::E; break;
case 'F': note = Note::F; break;
case 'G': note = Note::G; break;
default:
throw std::runtime_error("Wrong_note:"+tmp+"!");
}
return is;
}
std::istream & operator>>( std::istream & is, Pos & pos)
{
is >> pos.m_string >> pos.m_fret >> pos.m_note;
return is;
}
int main()
{
std::ifstream ifs("notes_on_frets.txt");
Pos pos;
std::vector<Pos> pos_v;
while( ifs >> pos) pos_v.push_back(pos);
}
|