I want to read a data from text file using structure and load it into vector.
so I wrote a following to do this but I failed to compile. I don't know what's wrong.
< what I did >
- text file contains data as follows;
835,5,0,0,1,1,8.994,0
(integer array[3], integer,integer,integer,integer,integer, float, Boolean)
2.I declared a structure contains following data types to load data into vector;
struct unfinished
{
int ans[3]; // contains answer
int max;
int st;
int ba;
int outs;
int tri;
float elapsed;
bool fin;
};
3.I wrote a code to read a data as follows;
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
struct unfinished
{
int ans[3];
int max;
int st;
int ba;
int outs;
int tri;
float elapsed;
bool fin;
};
vector<unfinished> read_rec(istream & is)
{
vector<unfinished> rec;
int ans[3];
int max, st, ba, outs, tri;
float elap;
bool fini;
while (is >> ans[0] >> ans[1] >> ans[2] >> max >> st >> ba >> outs >> tri >> elap >> fini)
{
rec.emplace_back(ans[0], ans[1], ans[2], max, st, ba, outs, tri, elap, fini);
}
return rec;
}
int main(void)
{
ifstream infile("unfin_rec.txt");
auto unfin = read_rec(infile);
vector<unfinished>::const_iterator it;
for (it = unfin.begin(); it != unfin.end(); it += 1)
{
cout << it->ans[0] << it->ans[1] << it->ans[2] << "," << it->max << "," << it->st << "," << it->ba <<","<<it->outs<<","<<it->tri<<","<<it->elapsed<<","<<it->fin<< endl;
}
system("pause");
return 0;
}
I failed to compile this code. error message was: >c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(600): error C2661: 'unfinished::unfinished' : no overloaded function takes 10 arguments
again, I couldn't figure out what this message means. Please help!
thanks,
seihyung
Aucun commentaire:
Enregistrer un commentaire