Here is the application of your code to my program:
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
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <vector>
#include <sstream>
class Draw
{
public:
int drawnumber;
long int drawdate;
int number1;
int number2;
int number3;
int number4;
int number5;
int number6;
int supp1;
int supp2;
};
std::ostream & operator << (std::ostream & os, const Draw & d)
{
os << d.drawnumber << ' ' << d.drawdate << ' ' << d.number1 << ' ' << d.number2 << ' ' << d.number3 << d.number4 << d.number5 << d.number6 << d.supp1 << d.supp2;
return os;
}
std::istream & operator >> (std::istream & is, Draw & d)
{
char ch;
is >> d.drawnumber >> ch >> d.drawdate >> ch >> d.number1 >> ch >> d.number2 >> ch >> d.number3 >> ch >> d.number4 >> ch >> d.number5 >> ch >> d.number6 >>
ch >> d.supp1 >> d.supp2;
return is;
}
using namespace std;
int main()
{
vector<Draw> MainVec;
ifstream myfile;
myfile.open("testdoc.txt");
if (!myfile)
{
cout << "Input file not open\n";
return 1;
}
Draw draw1;
while (myfile >> draw1)
MainVec.push_back(draw1);
for (const auto & a : MainVec)
cout << a << '\n';
}
|
Also, here is an example of the input file:
101,20160101,24,27,3,45,22,19,1,34
102,20160102,33,18,2,7,45,3,28,43
103,20160103,41,3,4,38,37,26,27,6
104,20160104,3,42,4,17,21,37,40,30
105,20160105,40,30,20,44,22,13,41
Having worked with it a bit, I've got it so that it runs but gives no output.
I will read up on Operator Overloading (I need to learn - I don't seriously expect you two write all my code for me, although I do appreciate everything you've done!) so I can better understand your code and apply this method in the future.
Again, many thanks for your assistance!