You might use a structure that exactl ymatches the line:
struct Record
{
char sz1[6];
char sz2[5];
...
};
Then you could read like
Record rec;
ifstream ifs("data.txt");
string line;
while (getline(ifs, line))
{
istringstream iss(line);
iss.read((char*)&rec, sizeof(Record));
if (!iss)
return; // error
rec.sz1[sizeof(rec.sz1)-1]
rec.sz2[sizeof(rec.sz2)-1]
...
v.push_back(rec); // put record to an array
Regards, Alex
Main Topics
Browse All Topics





by: Infinity08Posted on 2007-07-24 at 00:15:33ID: 19554034
Do a getline, and then process the line you got. Since you want to split it up at fixed indexes, that shouldn't be too hard ... substr should help :
eference/s tring/getl ine.html eference/s tring/stri ng/substr. html
oc/tutoria l/files.ht ml
http://www.cplusplus.com/r
http://www.cplusplus.com/r
Don't forget to check out the example code at the bottom of those pages.
For reading a file, check out this tutorial :
http://www.cplusplus.com/d