After reading this: C++ Writing to file and Console Output at the same time with simple code , I am trying to write a function to handle what I have in the for-loop. But I don't know how to pass a piece of code like this :setw(3) << right << get<0>(*it_party) << setw(9) << ""
altogether as an argument into a function so that both cout and file can use it.
The helper function I am trying to write:
void print(std::ostream &os1, std::ostream &os2, const [I don't know what to put in here])
{
os1 << the argument; // cout
os2 << the argument; // file
}
ofstream file;
file.open("test.txt");
for (auto it_party = parties_.begin(); it_party != parties_.end(); ++it_party) {
cout << setw(3) << right << get<0>(*it_party) << setw(9) << "";
file << setw(3) << right << get<0>(*it_party) << setw(9) << "";
cout << setw(7) << left << get<1>(*it_party) << setw(1) << "";
file << setw(7) << left << get<1>(*it_party) << setw(1) << "";
...
...
}