I had code like below. I feel like the file stream didn't reach the file end, because ln_cnt
value isn't equal to the feature count (i.e. number of polyline features) shown in QGIS.
Such inequality happend when the shapefile is large so I can't count features one by one, but I used small-sized shapefile for test already and my code works well.
polyline_class line_1;
int ln_cnt ++; // the counter for counting the lines that's read
ifstream reader("some_polyline.shp", ios::in | ios::binary);
while (!reader.eof()){
shp_read_pnt(&reader, &line_1);
ln_cnt ++;
}
cout << ".good() = " << reader.good() << "\n";
cout << ".bad() = " << reader.bad() << "\n";
cout << ".fail() = " << reader.fail() << "\n";
cout << ".eof() = " << reader.eof() << "\n";
cerr << "Error: " << strerror(errno);
reader.close();
The result is :
.good() = 0
.bad() = 0
.fail() = 1
.eof() = 1
Error: No error
Is there an error, actually ?
Aucun commentaire:
Enregistrer un commentaire