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 63 64 65 66 67 68
|
#include <iostream>
#include <iomanip>
#include <sstream>
#include <tuple>
#include <vector>
#include <algorithm>
using namespace std;
class Student
{
public:
Student()
: surname{}, lastname{}, courses{} {}
Student(string const & n, string const & l, string const & c)
: surname{n}, lastname{l}, courses{c} {}
friend istream & operator >>(istream & is, Student & s)
{
string surname;
string lastname;
string courses;
getline(is, surname, ',');
getline(is, lastname, ',');
getline(is, courses, ';');
istringstream nis{surname};
nis >> s.surname;
istringstream iis{lastname};
iis >> s.lastname;
istringstream cis{courses};
cis >> s.courses;
return is;
}
friend ostream & operator <<(ostream & os, Student & s)
{
return os << "({Surname}: " << s.surname << ", {Last name}: " << s.lastname << ", {Courses}: " << s.courses << ")";
}
private:
string surname;
string lastname;
string courses;
};
int main()
{
vector <Student> st(3);
int n{1};
for (Student & i: st)
{
cin >> i;
}
for (Student & i : st)
{
cout << i << endl;
}
return 0;
}
|